PYTHON
What is Python?
❑ Python is a popular programming language.
❑ It was created by Guido van Rossum, and released in 1991.
It is used for:
❑ web development (server-side),
❑ software development,
❑ mathematics,
❑ system scripting.
FIRST PROGRAM
Python Indentation
❑ Indentation refers to the spaces at the beginning of a code line.
❑ Where in other programming languages the indentation in code is for readability only,
the indentation in Python is very important.
❑ Python uses indentation to indicate a block of code.
❑ Python will give you an error if you skip the indentation
❑ You have to use the same number of spaces in the same block of code, otherwise
Python will give you an error
Python Comments
❑ Comments can be used to explain Python code.
❑ Comments can be used to make the code more readable.
❑ Comments can be used to prevent execution when testing code.
Creating Comment
❑ Comments start with # and can be placed anywhere ,and python will ignore them.
❑ A comment does not have to be text that explains the code, it can also be used to prevent Python from executing
code:
Multiline Comments
Variable
variables are created when you assign a value to it
Casting
If you want to specify the data type of a variable, this can be done with casting.
Get the Type
You can get the datatype of the variable using type() function.
.
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
Rules for Python variables:
❑ ● A variable name must start with a letter or the underscore character
❑ ● A variable name cannot start with a number
❑ ● A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,
and _ )
❑ Variable names are case-sensitive (age, Age and AGE are three different variables)
❑ A variable name cannot be any of the Python keywords.
Output Variables
The Python print() function is often used to output variables.
separated by a comma
You can also use the + operator to output multiple variables:
For numbers, the + character works as a mathematical operator: