Python Data types and Variables
INSCAE
Julliard Ph.D August 2024
Print statement
print("Hello world")
print(10)
print(4*5\n)
! Functions names are case sensitive
Arithmetic Operators
Comments
#This is a comment
print("Hello, World!")
print("Hello, World!") #This is a comment
"""
This is a comment
written in
more than just one line
"""
Arithmetic Operators
print(5+6)
print(5-2)
print(2*2)
print(5%2)
print(5**2)
print(5//2)
Variable assignment
x=3
y = “Mercredi”
print(x)
print(y)
Variable assignment
x=4 # x is of type int
x = "Sally" # x is now of type str
print(x)
Data types
Data types
x = "Hello World" str
x = 20 int
x = 20.5 float
x = 1j complex
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = {"name" : "John", "age" : 36} dict
Data types
x = {"apple", "banana", "cherry"} set
x = frozenset({"apple", "banana",
"cherry"}) frozenset
x = True bool
x = b"Hello" bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
x = None NoneType
Get Data Type
a = 5
print("Type of a: ", type(a))
b = 5.0
print("\nType of b: ", type(b))
c = 2 + 4j
print("\nType of c: ", type(c))
Variable Casting
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Multiple Variable Assignment
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Variable Assignment Shortcuts
Variable and Function Naming
Convention
module_name, package_name, ClassName,
method_name, ExceptionName, function_name,
GLOBAL_CONSTANT_NAME, global_var_name,
instance_var_name, function_parameter_name,
local_var_name
! Variable names are case sensitive
Variable and Function Naming
Convention
# Legal variable names:
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Sources
https://www.w3schools.com/python
Google Python Style Guide:
https://google.github.io/styleguide/
pyguide.html#316-naming