Lecture1 Py
Lecture1 Py
lege
ol
Translator
a C
(Compiler / Interpreter)
Machine
Apn Code
What is Python?
Python is simple & easy
lege
l
Free & Open Source
a
High Level Language
Co
Apn
Developed by Guido van Rossum
Portable
Our First Program
lege
Col
pna
A
print("Hello World")
Python Character Set
e
Letters – A to Z, a to z
Digits – 0 to 9
lleg
Co
Special Symbols - + - * / etc.
na
Whitespaces – Blank Space, tab, carriage return, newline, formfeed
p
A
Other characters – Python can process all ASCII and Unicode characters as part of data or literals
Variables
e
A variable is a name given to a memory location in a program.
lleg
a Co
name = "Shradha"
age = 23
Apn
price = 25.99
Memory
lege
Col
pna
A
name = "Shradha"
age = 23
price = 25.99
Rules for Identifiers
lege
Col
pna
A
Data Types
ge
Integers
String
olle
Float
na C
Ap
Boolean
None
Data Types
lege
Col
pna
A
Keywords
e
Keywords are reserved words in python.
lleg
Co
*False should be uppercase
pna
A
Print Sum
lege
Col
pna
A
Comments in Python
lege
# Single Line Comment
Col
"""
pna
A
Multi Line
Comment
"""
Types of Operators
An operator is a symbol that performs a certain operation between operands.
lege
ol
Arithmetic Operators ( + , - , * , / , % , ** )
na C
Ap
Relational / Comparison Operators ( == , != , > , < , >= , <= )
lege
l
a, b = 1, 2.0
Co
sum = a + b
pna
A
#error
a, b = 1, "2"
sum = a + b
Type Casting
lege
Col
a
a, b = 1, "2"
pn
c = int(b)
A
sum = a + c
Type Casting
lege
Col
pna
A
Input in Python
e
input( ) statement is used to accept values (using keyboard) from user
lleg
a Co
pn
input( ) #result for input( ) is always a str
A
int ( input( ) ) #int
pna
A
Let‘s Practice
lege
Col
WAP to input side of a square & print its area.
pna
A
Let‘s Practice
lege
Col
WAP to input 2 floating point numbers & print their average.
pna
A
Let‘s Practice
lege
Col
WAP to input 2 int numbers, a and b.
na
Print True if a is greater than or equal to b. If not print False.
Ap