Python 3 Introduction
Python 3 Introduction
BASIC SYNTAX
Python is an interpreted
language
• You can write programs interactively
using the interpreter
• a=b=c=1
• a, b, c = 1, 2, "john"
VARIABLE TYPES
Standard Data Types
• Python has five standard data
types-
– Numbers
– String
– List
– Tuple
– Dictionary
Output
Example
Output
Python Dictionary
• Dictionaries can hold key-value pairs.
– Similar to Map
– A dictionary key can be almost any
Python type, but are usually numbers
or strings.
– Values, on the other hand, can be any
arbitrary Python object
– Have no notion of order in data
• Dictionaries are enclosed by curly
braces ({ })
• Values can be assigned and
accessed using square braces ([])
Example
Output
Data Type Conversion
• To convert between the built-in types,
simply use the type-name as a
function.
• int(x [,base])
– Converts x to an integer. The
base (optional) specifies the base if x
is a string.
• float(x), complex(real [,imag]), str(),
chr()
• tuple(), list(), dict(), set()
BASIC OPERATORS
Operator Types
• Arithmetic Operators
• Comparison (Relational)
Operators
• Assignment Operators
• Logical Operators
• Bitwise Operators
• Membership Operators
• Identity Operators
• is
• not is
CONDITIONAL
STATEMENTS
If - Else
Nested If
:
Single Line If-Else
LOOP
S
Loops
• whil
e
Range
• The built-in function range() is used to iterate
over a sequence of numbers.
a= 10
print(mt.sqrt(10))
a= 10
print(sqrt(10))