0% found this document useful (0 votes)
7 views10 pages

Class 3

The document provides a comprehensive introduction to Python programming, covering basic concepts such as variables, data types, arithmetic and comparison operators, and logical operators. It includes examples of code snippets demonstrating the use of these concepts, along with explanations of multi-line comments and typecasting. Additionally, it showcases user input handling and basic mathematical operations using the math library.
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)
7 views10 pages

Class 3

The document provides a comprehensive introduction to Python programming, covering basic concepts such as variables, data types, arithmetic and comparison operators, and logical operators. It includes examples of code snippets demonstrating the use of these concepts, along with explanations of multi-line comments and typecasting. Additionally, it showcases user input handling and basic mathematical operations using the math library.
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/ 10

rr2xww80s

December 9, 2024

[ ]:

Basics of Python
[ ]: print ('welcome to python basics')

welcome to python basics

[ ]: print ("hello how are you")

hello how are you

[ ]: first_name = "praveen"
age = 36
marital_status = True
height = 5.5
laast_name = "kumar"

[ ]: print(first_name)
print(age)
print(marital_status)
print(height)
print(laast_name)

praveen
36
True
5.5
kumar

[ ]: type(first_name),type(age),type(marital_status),type(height),type(laast_name)

[ ]: (str, int, bool, float, str)

[ ]: type(laast_name)

[ ]: str

1
[ ]: laast_name.capitalize()

[ ]: 'Kumar'

[ ]: first_name.capitalize()

[ ]: 'Praveen'

[ ]: pi = 3.14

[ ]: type(pi)

[ ]: float

[ ]: pi.is_integer()

[ ]: False

[ ]: name = "chidrupa sai hello"

[ ]: name.split(sep="i")

[ ]: ['ch', 'drupa sa', ' hello']

[ ]: name1= "praveen kumar kandhala hello"

[ ]: name1.split(sep="a")

[ ]: ['pr', 'veen kum', 'r k', 'ndh', 'l', ' hello']

[ ]: name.split()

[ ]: ['chidrupa', 'sai', 'hello']

[ ]: name1.split()

[ ]: ['praveen', 'kumar', 'kandhala', 'hello']

[ ]: name.find("i")

[ ]: 2

[ ]: name.find("i",name.find("i")+1)

[ ]: 11

[ ]: name1.find("a")

2
[ ]: 2

[ ]: name1.find("a",name1.find("a")+1)

[ ]: 11

[ ]: print(5,6,3.14,"Hello world",'welcome to python basics')


a=10
#print(a)
a

5 6 3.14 Hello world welcome to python basics

[ ]: 10

VARIABLES OR IDENTIFIERS IN PYTHON


[ ]: A=10
a=20
print(A)
print(a)

10
20

[ ]: b=30
print(b)
b=40
print(b)
b=50
print(b)

30
40
50

[ ]: print(b)

50

[ ]: _name="python"
print(_name)

python

[ ]: Password="abc@123"
Password

[ ]: 'abc@123'

3
[ ]: _last_name="pqr"
_last_name

[ ]: 'pqr'

[ ]: a_23="xyz"
a_23

[ ]: 'xyz'

[ ]: #addition of two numbers


a=20
b=10
c=a+b
print(c)

30

[ ]: """
This is a multi-line comment.
We are making this comment.
"""

[ ]: ' \nThis is a multi-line comment. \nWe are making this comment.\n'

[ ]: '''
This is a multi-line comment
extending to multiple lines
'''

[ ]: '\nThis is a multi-line comment\nextending to multiple lines\n'

[ ]: '''
comment
'''

[ ]: '\ncomment\n'

[ ]: """
this
is
multi-line
comment
"""

[ ]: '\nthis\nis\nmulti-line\ncomment\n'

4
[ ]: '''
one
more
multi-line
comment
with
single-quotes
'''

[ ]: '\none\nmore\nmulti-line\ncomment\nwith\nsingle-quotes\n'

Arithmetic operators in python Basic operators + - * / // quotient % remainder ** power

[ ]: a=21
b=10
#addition
c=a+b
#subtraction
d=a-b
#multiplication
e=a*b
#division
f=a/b
#modulus
g=a%b
#Quotient
h=a//b

[ ]: print("Addition is:",c)
print("Subtraction is",d)
print("Multiplication is",e)
print("Divisiob is",f)
print("Remainder is",g)
print("Quotient is",h)

Addition is: 31
Subtraction is 11
Multiplication is 210
Divisiob is 2.1
Remainder is 1
Quotient is 2

[ ]: m=3
n=2
print(m**n)
print(n**m)

5
8
Comparision Operators
[15]: a=20
b=10

[16]: a==b

[16]: False

[17]: a>b

[17]: True

[18]: a<b

[18]: False

[19]: a>=b

[19]: True

[20]: a<=b

[20]: False

[21]: a!=b

[21]: True

Logical Operators And operator - if either of the conditions is false, it returns false: and True
and True returns True
True and False returns False
False and True returns False
False and False returns False
Or Operator - if either of the conditions are true, it returns a true: or True or True returns True
True or False returns True
False or False returns False
False or True returns True
Not operator - it will invert the boolean input: not not True returns False ! False returns True
[22]: True and True

6
[22]: True

[23]: True or False

[23]: True

[24]: False and True

[24]: False

[27]: not True

[27]: False

[28]: not False

[28]: True

[29]: (a,b)

[29]: (20, 10)

[30]: (a<=100) or (b>=10) #T or T

[30]: True

[31]: (a>=100) or (b>10) #F or F

[31]: False

[32]: (a<=30) and (b>10) #T and F

[32]: False

[33]: (a==20) and (b==10) #T and T

[33]: True

[35]: not (a==20)

[35]: False

[37]: not (b==20)

[37]: True

Basic typecasting in python

7
[38]: a=200
type(a)

[38]: int

[40]: b=3.234
type(b)

[40]: float

[41]: a=str(a)
a

[41]: '200'

[42]: a=float(a)
a

[42]: 200.0

[43]: b=int(b)
b

[43]: 3

[44]: b=str(b)
b

[44]: '3'

[45]: bool(a)

[45]: True

[46]: bool(b)

[46]: True

[49]: c=0
bool(c)

[49]: False

[50]: bool(20)

[50]: True

8
[51]: bool(-100)

[51]: True

[52]: bool(0)

[52]: False

input method
[53]: savings=input("How much You Saved?")

How much You Saved?20000

[54]: savings

[54]: '20000'

[56]: savings=int(savings)
savings

[56]: 20000

[63]: Weight=input("What is Your Weight?")

What is Your Weight?72.56

[64]: Weight

[64]: '72.56'

[65]: Weight=float(Weight)
Weight

[65]: 72.56

[67]: name=input("Please Enter Your name?")


age=input("Pleaase Enter Your age?")
salary=input("Please Enter Your salary?")
print("Hello Mr.",name,"Your age is:",age,"salary is:",salary)

Please Enter Your name?vinay


Pleaase Enter Your age?45
Please Enter Your salary?45600.50
Hello Mr. vinay Your age is: 45 salary is: 45600.50

[68]: # if the base of right angle traingle is 10 cm and hight of triangle is 20 cm.␣
↪find the hypoteneous of the triangle

9
# ans is square root of hight**2 + base**2

import math
base, height = 10, 20
hypotenuse = math.sqrt((base ** 2) + (height ** 2))
print("Hypotenuse = ", hypotenuse)

Hypotenuse = 22.360679774997898

[71]: import math


base=int(input("Enter base value?"))
height=int(input("Enter height value?"))
h=math.sqrt((base ** 2) + (height ** 2))
print("Hypotenuse=",h)

Enter base value?3


Enter height value?4
Hypotenuse= 5.0

10

You might also like