Review of Python

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Review of Python

What is Python?
•Python is a popular
programming
language created by
Guido van Rossum in
1991
Source:
https://education.ti.com/-/media/ti/t3-europe/images/blog/blog-python-blog-gu
ido.jpg?la=en&rev=95242eee-3bf7-4e81-9129-c182340f6f2e&hash=769F06
10FF480C27CC4D3344A24C4D4AEB2BAE73
Uses of Python

Web Software
development development

System
Mathematics
scripting
Why Python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi)
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages
• Python runs on an interpreter system
• Python can be treated in a procedural way, an object-oriented way or
a functional way
Latest version of Python on October 5, 2020

Source: https://www.debugpoint.com/blog/wp-content/uploads/2020/10/pythin39.jpg
Python Indentation
•Indentation refers to the spaces at the beginning of a code
line
Example:

if 5 > 2:
print("Five is greater than two!")
Python Comments
•Comments can be used to explain Python code
and make the code more readable
•Comments start with #
Example:
#This is a comment
print(“Hello, world”)
Variable Naming Conventions
•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)
Correct or Not?
1. myvar = "John“
2. 2myvar = "John“
3. _my_var = "John“
4. myVar = "John“
5. my var = "John"
Python Variable
•Variables are containers for storing data values
Example:
x=1
a, b=0,-1
a, b, c=0,-1, 2
Others:
b = “Sally” #This is a type of string
Casting

b="sally" #This is a type of string


b=int(4)
print(b)

b=float(4)
print(b)
Type() function
Example

x=5
y = "John"
print(type(x))
print(type(y))
“Double quotes” or ‘Single’ quotes
• String variables can be declared either by using single or double
quotes:

Example:
y = "John"
y = ’John’
Case sensitive
Example:

a=4
A = "Sally"
#A will not overwrite a
Multiple Variables

Example:
x, y, z = “one", “two", “three"
print(x)
print(y)
print(z)
One Value to Multiple Variables
Example:

x = y = z = "four"
print(x)
print(y)
print(z)
Output Variables
•The python print is used to output variables and
+ is used to combine both text and variable
Example:
x = “enjoying"
print("Python programming is " + x)
Other way:

x = "Python is "
y = “enjoying"
z= x+y
print(z)
Arithmetic Operations
Example:
x=5
y=3
print (x + y)

x=5
y=3
sum=x+y
sum
Assignment
Operators
Example:
a,b,c=0,-1,6
c%=3
c
Comparison Operators
Logical Operators
Example:
a,b,c=0,-1,6
a>b and c>b
True
Identity Operators
Example:

a,b,c=0,-1,5
a is c
False
Bitwise Operators
References
• Source: https://www.w3schools.com/PYTHON/python_intro.asp

You might also like