Friday, 6 November 2020

story about lion

 lion is the king of jungle but the lion have one enemy 

tiger is the enemy of lion tiger also like as same

but diferent in color

to be continue after 2 day.....

formula of phython and explain

 

Use print for all syntax:

Identity operator:

1)Python have tow identity operator:is’is not

Example:x=10

Y=10

If x is y

Orther ex:x=10

Y=20

If x is y

Is not example:

If x is not y:

Next topic: printing of a variable&string formatting:

Example:

Name=”phython”

Year=2020

Easy Printing type:

Print(f”name:  {name} year: {year}”)

Topic:input function

We want work calculator or programme calculator use this method:

Do not use this method:a=input(‘enter first number’)=10

                                          B=input(‘enter second number’)=20

                                           Ans=a+b=10=20

                                            Print(ans)=1020

Use this method:

>>>a=int(input())

10

>>>b=int(input())

20

Ans=a+b

30  this is the correct method

Topic:arithemetic operators

In python arithemetic operators have

For addition:+

Subtraction: -

Multiplication: *

Division:/    for division this type of slash only use /

 

Topic:power operator

** this the power operator of python

Example:

10**2=10power 2=100

5**3=5 power 3=125

Topic:floor division operator

// is the floor division operator of python

Example:

floor(4)=4

floor(4.5)=4

normal division example:

(10/2)=5.0

(20/5)=4.0

Floor division ex:

(5//2)=2

Topic:assignment operators:

 Name=”python”

Age=3

Price=0.00

(name)

“python”

(age)

3

(price)

0.00

We can do multiple assignment in python

Num1=num2=num3=0

(num1,num2,num3)

000

Multi value assignment:

This is basic assignment operator:

Name, pagecount, price= ”aaqil”, 300, 245.67   you want to space after coma you did not do like this: page  count      you did not use space while write string

(name,pagecount,price)

('python', 300, 245)

Topic:dicision making

Types of decision making statements:

*if

*if else

*nested if-else

*etc

Topic:needs of comments;

Comment is use to understand code

You want to command to tell what you do

You want to command before code

To add command use #

Ex: # app developer aaqil

Topic:escape sequence:

 

For new line to print: use n:and you want to use print in all escape cequeans

Print( “hello\nworld” )

Hello

World

For print after 4 space:print(“    \t    “)

Print(“hello\tjack”)

Hello    jack

For Single cotasion print:print(“     \”     \””)

Print('hello\'hello\'')

hello'hello'

for double cotasion print:print(“     \”     \””)

print("hello\"hello\"")

hello"hello"

for slash print:print(    \\    “)

print("hello\\hello")

hello\hello

how to print string without escape sequence:

example:

print(c:desktop\new.txt’)

n is escape sequence so ew.txt ws print in new line:

we want to use r befor c:

print(r’c:\desktonew.txt’)

c:\desktop\new.txt’)

r is use to ignoor escape seqences

 

 topic:indexing strings

example:

str=”phython”

in this string having six  character

in this string have index 0 t0 index 5

in this index we can acsess the string using the index number

example:

str=”phython”

print(“1st character”,str[0])

1st character p

Print(“4th character “,str[3])

4h character h

Print(str[100])

You print more than the chareter index means thorough

Out of range

We can identify the character index in reverse numbers

Like this:

P   y   t   h   o  n

-6 -5 -4 -3 -2 -1

Example:

Str=”phython”

Print(“last character”,str[-1])

last charecter n

topic:slicing string in python:

we can use slicing to slice a character with thenumber of string

befor the string number there was no numbers means python take as [0: ]

example:

 [:3] as [0:3]

and after the string number there was no number means python takes upto the last number of the string number::

example:

str=”python”

the string python have:0to5 in forward

and-1to-6 in reverse

next:

str=”python”

print(str[:3]) this python take as[ 0:3]

ans:pyt

print(str[-4:]) this python takes as[-4:-1]

ans:tho

we can not print the last string in python

and you want to print (str[0:3]) means

you got this type of ans:pyt but you did not get

pyth.python print the number we have enter at the last

before the number string will print in forward and reverse

topic:string methods:

we are going find the length of string:

str=”python”

print(len(str))

ans=6

replace a string:

str=”python”

new_str = str.replace("t", "T")

 print(new_str)

pyTHon

remove whitespace:

str ” python ”

 print(str.strip())

change string to upper case and lower case:

this is use to change small letter to capital letter capital letter to small letter

example:

str=”python”

print(str.upper())

ans:PYTHON

str=”PYTHON”

print(str.lower())

ans:python

split the string function:
str=”python,programme”

print(str.split(“,”))

ans:[‘python’, ’programme’]

str=”python-scripting-language”

print(str.split(“-“))

ans:[‘python’,’scripting’-‘language’]

topic:list

we can use one list to collect all data and store data

syntax:

variable=[item1,item2,itemn]

example:

colors=[“red”,”blue”,”green”]

print the list:

print=(colors)

ans:['hello', 'hell', 'hel', 'he', 'him']

orther ex:

data=[“python”,3.45,2018]

print(data)

['python', 3.0, 2018]

Hint:you can not use number as vareables

You can use any letter and word as variable

Topic:Indexting list:

I want to print 1st number means I want to use 0

I want to print 4th number means I want to use 3

Example:

Numbers=[10, 20, 30, 40, 50]

Print (“1st number “, number[0])

Ans:1st number 10

Print(“4th number “, number[3])

Ans:4th number 40


written by aaqil

 

 

 

 

 

 

 

 

 

 

 

 

story about lion

 lion is the king of jungle but the lion have one enemy  tiger is the enemy of lion tiger also like as same but diferent in color to be cont...