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

Python-3

This document provides an introduction to Python programming, covering key topics such as data types, variables, operators, and functions. It includes practical exercises for hands-on learning, demonstrating how to use print commands, accept user input, and perform calculations. Additionally, it lists resources for further learning and exploration of Python.

Uploaded by

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

Python-3

This document provides an introduction to Python programming, covering key topics such as data types, variables, operators, and functions. It includes practical exercises for hands-on learning, demonstrating how to use print commands, accept user input, and perform calculations. Additionally, it lists resources for further learning and exploration of Python.

Uploaded by

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

Introduction to Python

Session 3
What will you learn ?

• Introduction • Literals
• Introduction to Data Sets • Conditionals
• Concepts of Variables, Iterations & • Loops
Filtering • Functions
• Data Types • Lists & Tuples
• Sanity of Data • Sets & Dictionaries
• Introduction to Complex Data Types • File Handling
• Hands – On Python • Object Oriented Programming
Print Command in Python

Print - to give output on screen


Data Types in Python
1. Blue ones to represent a data & Dark Green ones is type to store the data

Strings Integers Floats


“a”,”SIES” -1, 100 -1.5, 3.3

Arrays / Dictionaries
Matrix

Boolean
True / Lists Tuples
False
Variables in Python

1. Simply – It is the name of the area of the hard-disk where a value is stored
2. For Ex. – X=55 ; we can say – 55 is stored in the hard disk and we can call the area
be X
3. Key rules of Variables in Python
• A variable must start with a letter or an underscore( _)
• A variable cannot start with a digit
• A variable can contain only alphanumeric characters and underscores - (A,a,
B,b, C,c 0123456789 ) or ( _)
• Variable names are case sensitive ( Age & AGE ) are different variables
• There is no limit to the length of the variable
• A Variable name cannot contain Spaces
• A variable name cannot be Python Key words
Key words in Python
Python keywords are special reserved words that have specific meanings and purposes and can't be used for
anything but those specific purposes.
Operators in Python
Mathematical & Logical Operators
Operators in Python

1. The // is called the floor division operator.


2. x // y gives the quotient when x is divided by y.
 For example, 8 // 3 is 2.
3. % is called the modulus operator.
4. x % y gives the remainder when x is divided by y.
 For example, 10 % 3 is 1.
5. ** is called the exponentiation operator.
6. x ** y returns x raised to y
 For example, 10 **2 is 100.
Operators in Python

Logical

The following table gives the logical operators and the operations that
they correspond to and or are binary operators; not is a unary operator.
Operator Operation

not Negation
and Logical conjunction
or Logical disjunction
Strings in Python
Strings in python are surrounded by either single quotation marks, or double quotation marks and contain all sorts
characters including space (‘ ’).
Indexing in Strings
This is how you will traverse any string and hence giving you some specific way in form of numbers to access a
particular position in the whole string.
Slicing in Strings
<StringName>[ start : end+1 ]
Exercises
# print 5 integers in an ascending order with one number in each line
print(1)
print(2)
print(3)
print(4)
print(5)

# print a following pattern


*****
****
***
**
*
print("*****")
print("****")
print("***")
print("**")
print("*")
Exercises
#accept an integer and print its square as output
import math
a=int(input("enter a no:" ))
b=a**2
print("the square of the no is",b)

#accept an integer a & integer b and print its sum as output


import math
a=int(input("enter a no1:" ))
b=int(input("enter a no1:" ))
sum=a+b
print("the sum of the number is ",b)
Exercises

#accept your car no as input & print its state code as an output
S=str(input("enter your car no "))
Scode=(S[0:2])
print("the state code is",Scode)

#accept a five-digit number as input and print the sum of its digits as output
num=int(input()

num=input()
D1=int(num[0])
D2=int(num[1])
D3=int(num[2])
D4=int(num[3])
D5=int(num[4])
DSUM=D1+D2+D3+D4+D5
print(DSUM)
Functions in Strings
Functions in Strings
Functions in Strings
Functions in Strings
Exercises
# Accept two positive integers M & N as input. There are two cases to consider
1) If M<N, then Print M as Output
2) If M>=N, subtract N from M and call the difference M1
3) if M1>=N, then subtract N from M1 and call the difference M2
Keep doing this until you reach the value k such that Mk<N
You have to print the value of Mk as output

Ans :---
Resources

• https://drive.google.com/drive/my-drive

• https://www.python.org/

• https://www.python.org/psf/

• http://www.replit.com/

• https://docs.replit.com/tutorials/introduction-to-the-repl-it-ide

You might also like