Crash Course on Python Programming
Python is a computer programming language and it can be used to build web applications on a server.
Features of Python
- web development (server-side),
- software development,
- system scripting.
Python can be used as:
1.Web applications can be developed on a server using Python.
2.Workflows can be made with Python and other technologies.
3.Database systems are connectable with Python. Files can also be read and changed by it.
4.Big data management and advanced mathematical operations can both be done with Python.
5.Python can be used to produce software that is ready for production or for rapid prototyping.
The spaces at the start of a code line are known as indentation.
Python’s indentation is crucial, unlike other programming languages where it just serves to make the code easier to understand.
A block of code is indicated via indentation in Python.
Python offers the ability to add comments for in-code documentation.
When a comment begins with a #, Python will treat the remaining characters in the line as comment
Python code can be explained using comments.
Code can be made more readable by using comments.
When testing code, comments can be used to stop execution.
#This is a comment.
Data values are kept in variables as storage.Declaring a variable is not a command available in Python.When a variable is initially given a value, it is considered to have been formed.
x = 1
y = “Anjali”
Casting can be used to define a variable’s data type if you want to.
Also Read: About Python programming
A variable’s name might be short (like x and y) or longer (like age, carname, or total volume). Python variable rules:
1.The underscore character or a letter must come first in a variable name.
2.No number may begin a variable name.
3.Only underscores (A-z, 0-9, and _) and alphanumeric characters are permitted in variable names.
4.Names of variables are case-sensitive (age, Age and AGE are three different variables)
Global variables are those that are produced outside of a function, like in all of the aforementioned cases.
Everyone can utilise global variables, both inside and outside of functions.
Normally, a variable created within a function is considered local and can only be utilised within that function.
Use the global keyword to define a global variable within a function.
Python Data Types
Different forms of data can be stored in variables, and different types can perform various functions.
The following categories of data types are included by default in Python:
In Python, there are three types of numbers:
Int:A full number, positive or negative, without decimals, and with an indefinite length is known as a “integer.”
float:A number with one or more decimals, whether positive or negative, is referred to as a float
complex: The imaginary portion of complex numbers is represented by the letter “a”.
Although Python does not have a built-in random() function, it does contain a random module that can be used to generate random numbers.
In Python, strings are enclosed in either single or double quotation marks.
The slice syntax allows you to return a range of characters.
To return a portion of the string, enter the start index and the end index, separated by a colon.
The string is returned by the upper() method in all caps.
Lowercase letters are returned by the lower() method.
Whitespace is the blank space that appears before and/or after the actual text, and you should usually eliminate it.
A string is replaced with another string using the replace() method
The text between the chosen separator is used as the list elements when the split() method returns a list.
Use the + operator to concatenate, or merge, two strings.
We discovered that we cannot combine strings and numbers in this way in the Python Variables .
But by utilising the format() technique, we can combine texts and numbers!
The given arguments are formatted using the format() method, which also inserts them into the string in the appropriate placeholders.
Use an escape character to inserted prohibited characters into a string.
Backslashes and the character you want to insert are considered escape characters.
A double quotation inside a string that is surrounded by double quotes is an illustration of an unlawful character.
You can use a variety of built-in methods on strings in Python.
You frequently need to know whether an expression in programming is True or False.
In Python, you may evaluate any expression to see whether it is True or False.
Operations on variables and values are carried out using operators.
The + operator is used to combine two values in the example below.
The operators in Python are split into the following categories:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators
- Identity operators
- Membership operators
- Bitwise operators
Arithmetic Operators: Common mathematical procedures are carried out using arithmetic operators and numeric quantities.
Assignment Operators: To assign values to variables, utilise assignment operators.
Comparison Operators: To compare two values, comparison operators are employed.
Logical Operators: Conditional statements are combined using logical operators.
Identity Operators: Identity operators are used to compare objects to determine if they are the same object in the same memory address rather than if they are equal.
Membership Operators: To determine whether a sequence is contained in an object, membership operators are employed.
Bitwise Operators: Binary number comparisons are performed using bitwise operators.
Also Read :About Eclipse
Leave a Comment