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

Python Day-2

Uploaded by

leenakatkar60
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 views12 pages

Python Day-2

Uploaded by

leenakatkar60
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/ 12

Rudraksha Welfare Foundation

Python Strings

a = "Hello"
print(a[1]) #e

Hel l o
01234
Index start from 0

print(len(a)) #5

Length of string 5
Lets search the free text in the following text.

txt = "The best things in life are free!"


print("free" in txt)

It will print True


Slicing Negative Indexing
Use negative indexes to start the
b = "Hello, World!" slice from the end of the string:
print(b[2:5])
b = "Hello, World!"
# llo print(b[-5:-2])

b = "Hello, World!" Output:


print(b[:5]) orl

# Hello
Python For Loops

for x in range(6):
print(x)
Python For Loops

for x in range(2, 30, 3):


print(x)
Python While Loops

i=1
while i < 6:
print(i)
i += 1
Python While Loops

i=1
while i < 6:
print(i)
i += 1
1. Print series 10 20 30 40 50 60 70 using for loop

2. Print table of 2 using for loop

3. Print factorial of a number using while loop


N! = 5! = 5 x 4 x 3 x 2 x 1 =120

4. Print even numbers from 1 to n using while loop

You might also like