0% found this document useful (0 votes)
8 views

Lecture1 Py

Introduction to python

Uploaded by

221123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture1 Py

Introduction to python

Uploaded by

221123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

ProgrammŤng

Translator
(CompŤler / Interpreter)

MachŤne Code
What Ťs Python?
Python Ťs sŤmple &

easy Free & Open

Source HŤgh Level

Language

Developed by GuŤdo van Rossum

Portable
O u r F Ťr s t P r o g r a m

print("Hello World")
Python Character Set
Letters – A to Z, a to
z DŤgŤts – 0 to 9
SpecŤal Symbols - + - * / etc.
WhŤtespaces – Blank Space, tab, carrŤage return, newlŤne, formfeed
Other characters – Python can process all ASCII and UnŤcode characters as part of data or lŤterals
VarŤables
A varŤable Ťs a name gŤven to a memory locatŤon Ťn a program.

name =
"Shradha" age =
23
price = 25.99
Memory

name =
"Shradha" age =
23
price = 25.99
Rules for IdentŤfŤers
Data Types
Integers
StrŤng
Float
Boolean
None
Data Types
Keywords
Keywords are reserved words Ťn python.

*False should be uppercase


PrŤnt Sum
Comments Ťn Python

# Single Line Comment

"""
Multi Line
Comment
"""
Types of Operators
An operator Ťs a symbol that performs a certaŤn operatŤon between operands.

ArŤthmetŤc Operators ( + , - , * , / , % , ** )

RelatŤonal / ComparŤson Operators ( == , != , > , < , >= , <= )

AssŤgnment Operators ( = , +=, -= , *= , /= , %= , **= )

LogŤcal Operators ( not , and , or )


Type ConversŤon

a, b = 1, 2.0
sum = a + b

#error
a, b = 1, "2"
sum = a + b
Type CastŤng

a, b = 1, "2"
c = int(b)
sum = a + c
Type CastŤng
Input Ťn Python
Ťnput( ) statement Ťs used to accept values (usŤng keyboard) from user

input( ) #result for input( ) is always a str

int ( input( ) ) #int

float ( input( ) ) #float

gŤve code eg of all 3


Let‘s PractŤce
WrŤte a Program to Ťnput 2 numbers & prŤnt theŤr sum.
Let‘s PractŤce
WAP to Ťnput sŤde of a square & prŤnt Ťts area.
Let‘s PractŤce
WAP to Ťnput 2 floatŤng poŤnt numbers & prŤnt theŤr average.
Let‘s PractŤce
WAP to Ťnput 2 Ťnt numbers, a and b.
PrŤnt True Ťf a Ťs greater than or equal to b. If not prŤnt False.

You might also like