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

AI Python Notes

The document provides an overview of Python as a popular multi-paradigm programming language, developed by Guido Van Rossum in the 1990s. It covers fundamental concepts such as tokens, operators, data types, variable declaration rules, keywords, and type conversion. Additionally, it includes examples of basic Python programs for practice.

Uploaded by

Karan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AI Python Notes

The document provides an overview of Python as a popular multi-paradigm programming language, developed by Guido Van Rossum in the 1990s. It covers fundamental concepts such as tokens, operators, data types, variable declaration rules, keywords, and type conversion. Additionally, it includes examples of basic Python programs for practice.

Uploaded by

Karan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Language

A way to communicate with others.

Program
Set of Commands/Instructions.

Programming Language
A way to write set of Instructions.
Ex- Python, C, C++, Java, C#.........

Computer Department
Python is a very popular
programming language among
beginners as well as developers.
Python is an Multi-paradigm
language.

PYTHON LANGUAGE
Python was
designed for
Socket
Python was developed by Programming
Guido Van Rossum in 1990s.
Python was named after the BBC
comedy series ‘Flying Circus’ of
Monty Python. Computer Department
Tokens/Lexical unit
The smallest individual unit in a program is
known as a token.
Python has following tokens:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators

Computer Department
Operators
Arithmetic operators
+(Addition), -(Subtraction),
*(Multiplication), //(Floor Division),
/(divide), %(Modulus), **(Power)

Ex- A=10 ,B=3


A+B=13,
A-B=7,
A*B=30, A**B=1000
A//B=3, A/B=3.33 , A%B=1
Computer Department
Relational operators
>(Greater than), <(Less than),
>=(Greater than equal to),
<=(Less than equal to),
==(Equal to), !=(Not Equal to)
Ex- A=10, B=20
A>B (False)
A<B (True)
A>=B (False)
A<=B (True)
A==B (False), A!=B(True) Computer Department
Logical operators
and , or, not
Ex-
A B A and B A or B not B
T T T T F
T F F T T
F T F T F
F F F F T

Computer Department
Membership operators
In, not In
Ex-
10 in [10,20,30,40,50]
True

10 not in [10,20,30,40,50]
False

Computer Department
DATA TYPES

Numbers
String
List
Complex
Tuples
Integer Dictionary
Floating point
Computer Department
Immutable Mutable
▪ Tuple ▪ List
▪ String ▪ Dictionary
▪ Number
Python Screen

Interactive mode Script Mode

Computer Department
Print() Statement
Use to give output or show message on screen.
Ex-
Print(“Welcome to Python”)

Input() Statement
Use to get data/information/string from user.
Ex-
A=input(“Enter your name”)
Or
A=int(input (“Enter a number”))
Computer Department
Variable
Labeled storage location, whose value can be
manipulated during program run.
But python variables are not storage containers,
rather python variables are lie memory references.
Ex- A=10 # Integer value
Name=“Rohan” # String value
A=B=C=10 # Multiple Assignment
A,B,C=10,20,30 #Multiple value to multiple
variable.
Comments in Python
Single line = # Single line comment
Multiple line = ””” Multi line comment”””
Computer Department
Rules to declare Identifier/Variable
•It Cannot start with a digit
•It can contain letters , digits or
underscore
•Punctuation and blanks are not allowed
•Python is case sensitive. The identifier
total is different form Total.
•Keywords cannot be used as a variable.

Computer Department
KeyWords
These are reserved words that have a pre-
defined meaning to the interpreter. They are
Easy to recognize in IDLE because they are
automatically colored orange.
Keywords in Python:
and def for is return
as del from lambda try
assert elif global not while
break else if or with
class except import pass yield
continue finally IN raise print
Computer Department
#Write a program to enter two numbers
from user and find sum of them.

a=int(input("Enter first number"))


b=int(input("Enter second number"))
c=a+b
print("Sum=",c)

Computer Department
Programs to practice
•Write a program to enter two numbers from user and
find sum of them.
•Write a program to enter two numbers from user and
find difference of them.
•Write a program to enter a number from user and find
area of square.
•Write a program to enter two numbers from user and
find area of rectangle.
•Write a program to enter Height and Radius from user
and find area of triangle.
•Write a program to enter two numbers from user and
swap values.
Computer Department
#Write a program to enter a number
two numbers from user and swap
values.

a=int(input("Enter first number"))


b=int(input("Enter second number"))
c=a
a=b #a , b = b , a
b=c
print(“value swapped=",a,” ”,b)

Computer Department
Type Conversion
Conversion of a type of value into another.
It is of two types.
•Implicit conversion
Conversion done by compiler itself. Also called
Automatic conversion. No data lose.
Ex- a=4.5+5
print(a) # 9.5
•Explicit conversion
Conversion done by user intervention. Also called
type casting. Data lose can occur.
Ex- a=int(4.5+5)
print(a) #9
Computer Department

You might also like