Python Syntax,
Variables
Introduction
Mariam Fakih 2
Outlines
• Visual Studio
• Jupyter
• Python expressions
• Python Variables
• Comments
• Variables Operations
• User input
• Data types
• Summary
3
Visual Studio steps
• Create a project
4
Visual Studio steps
• Choose Python as language
and choose create
5
Visual Studio steps
• If Python doesn’t exist, Go to VS
installer, and choose to install it
6
Visual Studio steps
7
Jupyter Notebook
• Download Anacondas
• Open Jupyter
8
Jupyter
9
Jupyter Notebook in Browser
• Create a new notebook
10
New NoteBook
• Start coding!
11
Python expressions
Input/output
• Run using shift/ctrl
12
Python Variables
• A variable stores a piece of data, and gives it a
specific name.
• The variable’s name can be anything but must
not begin with numbers or special characters.
• We store a number or a text or a list or any other
type to a variable by assigning a value to it.
• Every variable has a type, the type of a variable is
the type of the data assigned to it
13
Python Variables
• The principles of naming conventions are:
• Names must have one word, that is, with no spaces
• Names must only comprise of letters and numbers
also as underscores like (_)
• Multiword can be declared as “theMultiWord” or
“TheMultiWord”
• Reserved words must not ever be used as variable
names.
14
Python Variables
• You can change the value of a variable by
"reassigning" it, like this:
– name=34 #type integer
– name='Machine Learning' #type string
15
Declaring Variables
16
Assigning multiple value
• We can assign multiple value at the
same time (unpacking):
x , y = 7 , 9
print(x+y, x-y, x*y, x/y, x**y)
x , y = 3 ,'13'
print(x)
print(y)
17
Variables operations
x,y=3,'13'
name='Mariam'
print(x*y)
print(x*name)
print(y+name)
print(y+" "+name)
print(name*3)
#print(x+y) error
18
Comments
• Comments in Python are the lines in the code that are ignored
by the interpreter during the execution of the program.
• Comments enhance the readability of the code and help the
programmers to understand the code very carefully.
• There are three types of comments in Python:
• Single line Comments # sample comment
• Multiline Comments
# Python program to demonstrate
# multiline comments
OR
""" Python program to demonstrate
multiline comments"""
19
Variables operations
• Operation sum with integer and String
x,y=3, '13'
print(x+y)
print(str(x)+y)
print("X="+str(x))
20
User Input
• Ask the user for input:
name=input("enter your name: ")
print(name)
print(type(name))
age=input("enter your age: ")
print(age)
print(type(age))
21
Operations with user input
x=input("enter a number: ")
y=input("enter a number: ")
print(x*2)
print(x+y)
#print(x-y) error
x=int( input("enter a number: ") )
y=int( input("enter a number: ") )
print(x*2)
print(x+y)
print(x-y)
22
Exercise
• Create two text variables called “name”
and “age” and ask the user to give their
name and age.
• Print these two variables like this:
“your name is……., you
are…….years old”.
23
Exercise
• Ask the user to input x and you will print y
in this form f(x)=…, ex. f(2)=19
• f(x)=2x2
+3x+5
24
Data types
• Integers: 2323, 3234L
• Floating Point: 32.3, 3.1E2
• Complex: 3 + 2j, 1j
• Boolean
• String
• Lists: l = [ 1,2,3]
• Tuples: t = (1,2,3)
• Dictionaries: d = {‘hello’ : ‘there’, 2 : 15}
– Lists, Tuples, and Dictionaries can store any
type (including other lists, tuples, and dictionaries!)
– Only lists and dictionaries are mutable
– All variables are references
25
Data types
i=3
print(i)
print(type(i))
fl=0.666
print(fl)
print(type(fl))
c1,c2=1j,2j
print(c1,c2)
print(type(c1))
s='text’
print(s)
print(type(s))
b=True
print(b)
print(type(b))
26
Summary
• In Python, type checking is deferred until runtime.
• There's no need to declare a variable name and type prior to using
the variable in an assignment statement.
• A variable is introduced by assigning a value to it. Example:
someVariable = 42
• Python supports the following built-in data types:
– Plain integers (normally 32-bit integers in the range -
2147483648 through 2147483647).
– Long integers (size limited only by memory size of the machine
running on)
– Booleans (False and True).
– Complex numbers.
• In addition, Python supports a number of types that represent a
collection of values - including strings, lists, and dictionaries.

01-Python syntax &Variables(for beginners).pptx