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.
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are
called statements.
The following statement prints the text "Python is fun!" to the screen:
print("Python is fun!")
Text in Python must be inside quotes. You can use either " double quotes
or ' single quotes:
print("This will work!")
print('This will also work!')
However, unlike text, we don't put numbers inside double quotes:
print(358)
print(50000)
You can combine text and numbers in one output by separating them with a
comma
print("I am", 13, "years old.")
Python Comments
Comments start with a #, and Python will ignore them:
#This is a comment
print("Hello, World!")
Python Variables
Variables are containers for storing data values. A variable is created the moment
you first assign a value to it.
Example
x=5 # x is of type int
y = "John" # y is of type str
print(x)
print(y)
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.
DATATYPES
Variables can store data of different types, and different types can do different
things.
Python has the following data types built-in by default
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
Python Operators
Operators are used to perform operations on variables and values.