Python Training Tutorials
Python Training Tutorials
How to do print:
What is command in print
String is used in double qoutes”raj”
Simple ()
First Python Program
----
light= speed_of_light *60
Print (light)
Another way to declare variables in
python
• Hours=(9)
• Hours= (hours+1)
• Hours=(hours*2)
• Print(hours)
String
• It is a combination of words within double
quotes.
• Example
• Print(“my name is”+ kamran)
• Print(“my name is”+”kamran”)
• Print(“my name is”*2)
How to print values from strings
• X=(“abcded”)
• Suppose we want to print c in above string
• The values like this.. 0,1,2,3…..
• Print(x[2])
• c
String in Python Programing
Abc=(“computer)
Print(abc[-6])
========
How to use colon in string.
Abc=(“computer”)
Print(abc[1:])
It will print omputer.
===========
Print(abc[:-2])
It will print comput
Out of range number will give the blank output.
abc=(“computer”)
Print(abc[50:])
It give blank output.
- If we will give out of range value at the end. i.e.
Abc=(“computer”)
print(abc[:40])
Then it will print whole string i.e. computer.
- If we will not give any value then it will print whole string i.e.
Abc=(“computer”)
Print(abc[:])
- You can also print seperated alphabets in strings.
abc=(“computer”)
Print(abc[0:3] +abc[3:])
-if you give the values out of range then it will print whole string.
abc=(“computer”)
Print(abc[0:60] +abc[60:])
Selecting sub sequences in Python
Programming
• [Starting point: ending point]
Abc =(“computer”)
Print(abc[1:3])
Search Engines
• Duck duck go
• Dave Dave Find
• Google
• Bing
• Yahoo
Search Engine Concepts
<html>
<head>
<title> Professionals Lab</title>
</head>
</body>
<b> This is fast growing IT Company in India</b>
<a href="www.facebook"> facebook</a>
</body>
</html>
This simple example of a href tag.
How search engine work
• Search engine first search the a href code in
source code file.
• Then extract the website link
• Within this search double qoutes”” within <a
href = “ www.facebook.com”
• Then index one by one then show the result.
Example of search in python
page=('…<a href="www.facebook">facebook</a>……')
start_link=(page.find('<a href'))
start_qout=(page.find('"',start_link))
end_qout=(page.find('"',start_qout +1))
url=(page[start_qout+1:end_qout])
print(url)
Find Operator in Pythor
• it is used to find position in string using find operator. syntax- print(abc.find(“m”).
Example.
Abc(“computer”)= to find the position of m
Print(abc.find(“m”).
Example for find position in a line.
Abc=(Hi, I am going delhi for interview)
-Print I position in above line.
abc=(“Hi, I am going at Delhi for interview)
Print(abc.find(“p”)
-if you want to print g after that rest of the line.
Abc=(“Hi, I am going to delhi for interview”)
y=(abc.find (“g”)
Print(abc[y:])
* Abc & y are variables.
Exp.
Abc=(“computer”)
Y=(abc.find(“interview”)
Print(y)
-How to find word which is not available in paragraph.
Abc=(“computer”)
Y=(abc.find(“love”)
Print(y)
In this case it will display -1 only.
Abc=(“computer”)
Y=(abc.find(“love”)+5)
Print(y)
In this case it will print 4 only.
How to use number in find operator
I am love you so much, my love.
-how to find values of second same word.
abc=("I love you so much, my love")
a =(abc.find("love"))
b =(abc.find("love",a+1))
print(b)
Or
Print(abc[b:])
It will display after love, rest of the line.
Input Function in Python
• Q .requesting input, program- Hello,-What is your
name- hello nice to meet you.
• Ans.
# requesting input function
#program -Hello- What is your name- Nice meet to
you.
print("Hello")
x= input("What is your name")
print("Hello, Nice to meet you")
Len,int,str() functions in Python
• Len() – it is used to find the character length of string.
- x=(“Computer”)
Print(len(X))
==========
Str() function –it is used to convert values in string
# print- Hello- what is your name
# give the output.
print("Hello")
x= input("what is your name")
print("length of your name is" + str(len(x)))
Int() Function
Int() function- it is used to convert the value
from string to integer.
Example.
x=("25")
y=(int(x))
print(5+y)
Q . Write a program using
str(),len(),int() functions.
# print hello
# ask- Name
#output - length of name
# ask= age
#output= you will be age + 1 in a year
# str,len, int,input, variables.
print("hello")
x = input(" what is your name")
print(x + "length of your name is" + str(len(X))
y = input("what is your age")
print(("you will be") + str(int(y)+1) + (" in a year"))
The Sum of Two numbers:
#sum of two numbers in python
print("wellcome, the sum of two number")
x=input("Enter First number")
x=int(x)
y=input("Enter two number")
y=int(y)
print(("The sum of two number is ") + str(x+y))
Procedure and Function in Python
def position2(search,target):
first=(search.find(target,first+1))
hobby=("i like to paly ball and i am learning ball")
y=(position2(hobby,"guitar"))
print(hobby[y:])
Decision control – if Statement
# decision control- ==(equal to),= (assingnment Operator)
Print(“welcome, this is number guessing, and no is in”)
X= input(“guess the number”) # if statement
X=input(x)
If(x==4):
print(“your guess is right, great, you win”)
If(x!=4):
print(“oops, your guess is wrong”)
If- else statement
# decision control- ==(equal to),= (assingnment
Operator)
Print(“welcome, this is number guessing, and no is
in”)
X= input(“guess the number”) # if statement
X=input(x)
If(x==4):
print(“your guess is right, great, you win”)
else(x!=4):
print(“oops, your guess is wrong”)
Write a program of two number which is greater then