0% found this document useful (0 votes)
4 views4 pages

Python Fundamentals Handouts

The document provides an overview of Python, highlighting its features as a high-level interpreted programming language created by Guido van Rossum in 1991. It covers basic programming concepts such as output, input, keywords, and various types of operators including arithmetic, relational, and logical operators. Additionally, it includes examples of code and their outputs to illustrate these concepts.
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)
4 views4 pages

Python Fundamentals Handouts

The document provides an overview of Python, highlighting its features as a high-level interpreted programming language created by Guido van Rossum in 1991. It covers basic programming concepts such as output, input, keywords, and various types of operators including arithmetic, relational, and logical operators. Additionally, it includes examples of code and their outputs to illustrate these concepts.
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/ 4

Fundamentals of Python

• Python (a computer language) :


➢ Python is a powerful and high level language and it is an interpreted language.
➢ It is widely used general purpose, high level programming language developed by Guido van Rossum in 1991.
➢ Python has two basic modes: interactive and script.In interactive mode (python.exe/py.exe), the result is returned
immediately after pressing the enter key. In script mode (IDLE), a file must be created and saved before executing
the code to get results.
Basics of Python: Output
Simple Hello world Program Output
print('hello world') hello world
print("HELLO WORLD") HELLO WORLD

Declaring/Defining variable Output


a=10 30
b=20 23
c=a+b
print(c)
d,e=2,3
print(d,e)
Output Formatting Output
a,b=10,20 The addition of a and b is 30
c=a+b The addition of 10 and 20 is 30
print("The addition of a and b is ", c) The addition of 10 and 20 is 30
print("The addition of ",a,"and ", b, "is ",c)
print("The addition of %d and %d is %d" %(a,b,c))
name="XYZ" Output
age=26 The age of XYZ is 26 and salary is 65748.93
salary=65748.9312
print("The age of %s is %d and salary is %.2f"%(name,age,salary))

Basics of Python: Input


Accepting input without prompt Output
name=input() Govind
print(name) Govind

Accepting input with prompt Output


name=input(“Enter your name : ") Enter your name : Govind
print("My name is ",name) My name is Govind

Accepting formatted input (Integer, float, etc.) Output


a=int(input("Enter any integer number :")) Enter any integer number :10
b=float(input("Enter any float number :")) Enter any float number :3.14
print("Entered integer is : ",a) Entered integer is : 10
print("Entered float is : ",b) Entered float is : 3.14

Keywords in Python
There are 33 keywords in Python 3.7. This number can vary slightly in the course of time. All the keywords except True, False and
None are in lowercase and they must be written as it is. The list of all the keywords is given below.
and del from not while as elif global or with assert else if pass yield
break except import print class exec in raise continue finally is return def for
lambda try
Operators in Python
Python language supports the following types of operators-
• Arithmetic Operators
• Relational Operators
• Assignment Operators
• Logical Operators
• Bitwise Operators
• Membership Operators
• Identity Operators
Operators in Python: Arithmetic
Assume a=10 and b=20

Operators in Python: Relational

Relational Operators are used to show relationship between two values or variables. Following are the relational operators
< (less than), >(greater than) , <= (less than equal to), >= (greater than equal too) ,!= (Not equal to) and = = (equality check
operator)
Logical Operator in Python
Operators in Python: Assignment

Operators in Python: Bitwise

Bitwise operator works on bit and performs bit by bit operation. Assume if –
A=60 and B=13; now in binary they will be as follows
A(60)=00111100
B(13)=00001101

a&b = 0000 1100 (Use of bitwise Binary AND)


a|b = 0011 1101 (Use of bitwise Binary OR)
a^b = 0011 0001 (Use of bitwise XOR)
~a = 1100 0011 (Use of ones complement)
Operators in Python: Membership

list=[1, 2, 3, 4, 5] Output
print("Elements in the list: ",list) Elements in the list: [1, 2, 3, 4, 5]
if(3 in list): 3 available in the list
print(3, "available in the list")
else:
print(3, "Not available in the list")

Operators in Python: Identity

a,b = 20,20 Output


print("ID of a :",id(a)," ID of b :",id(b)) ID of a : 1442604432 ID of b : 1442604432
if(a is b): a and b have same identity
print("a and b have same identity")
else:
print("a and b do not have same identity")

You might also like