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

Pyhton 1

The document discusses various Python concepts like string manipulation, lists, tuples, sets, dictionaries, and data types. It provides examples of using string indexes and slices, built-in list methods like append and pop, basic data types like integers and floats, and functions for converting between number systems like binary, octal and hexadecimal.

Uploaded by

Ashish Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Pyhton 1

The document discusses various Python concepts like string manipulation, lists, tuples, sets, dictionaries, and data types. It provides examples of using string indexes and slices, built-in list methods like append and pop, basic data types like integers and floats, and functions for converting between number systems like binary, octal and hexadecimal.

Uploaded by

Ashish Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Page 1 of 5

1. // represents integer division of---------- 2//3=8 and ** represents power of.

2. For string either use '' or "" but

case 1: print('naveen's laptop')=error

case 2: print('naveen\'s laptop')=naveen's laptop

3. If you use '' outside then it is fine to use '' inside"" and vice versa.

case1: print('naveen "laptop"')=naveen "laptop"

case2: print("naveen's laptop")=naveen's laptop

4. Underscore ('_') represents previous output

case: x=2 , y=3

x+9=11

_ +y=14

5. If a variable stores a string then, we can access arrays also

case1: name='ashish'

name[0]='a'

case2: If negative integer is used then, the element's counting starts from right
to left----------ashish(-6,-5,-4,-3,-2,-1)

name[-1]='h'

6. For printing more than one element of a string array then we use --- name[a:b]=where
a is starting element postion and b is how many elements have to be printed starting from
name[0]

case1: name[0:3]='ash'

case2: name[2:4]='hi'
Page 2 of 5

case3: name[2:]='hish'

case4: name[:3]='ash'

case5: name[2:10]='hish'

7. If we want to replace some elements of string 'ashish' , it is NOT possible in the


following manner----- name[0]='b'

But we can do it by cancatenating it like ---

'b'+name[1:5]='bshish'

8. Functions--------------

a. len= to know the string lenght of a variable

9. Lists------- Same as arrays

 can contain same types of elements

 can contain different types of elements

 a list can contain two or more lists as well

num=[1,2,3,4,5]

name=['a','b','c','d']

mix=[num,name]

mix=[1,2,3,4,5],['a','b','c','d']

10. Function used in lists:-

num=[1,2,3,4]

 append=used to extend the list by adding elements in the last of the list

num.append(6)

num=[1,2,3,4,6]

 insert=used to add element in between the list.


Page 3 of 5

num.insert(2,5) where 2 is the index and 5 the element to be


added

num=[1,2,5,3,4,6]

 remove=used to remove an element from the list

num.remove(2)

num=[1,5,3,4,6]

 pop=used to remove elemets from the list when index no. is given

num.pop(2)

num=[1,5,4,6]

If no index no. is given then, the last element will be removed


using pop function

 del=used to delete more than one element from the list

del num[2:4]

num=[1,5]

 extend=used to add more than one element in the list

num.extend([7,8,9])

num=[1,5,7,8,9]

 min=used to find out the minimum value in the list

min(num)=1

 max=used to find the maximum value in the list

 sum=used to find the sum of all the elements of the list

sum(num)=30

 sort=used to sort the elements of the list in ascending order

 count=used to count the occurance of an element


Page 4 of 5

11. Tuple :-

It is used when an user wants that the elements can not be changed. Instead of
square brackets , small brackets are used

12. Set:-

Set is same as lists but it does not follow any specific order. { } are used to represent
set. A set does not support duplicate values.

13. Use help() to get documentation of python.

14. Data Types:----------------------------------It can be checked using type(variable):-

 None--------- when the data type of the variable is not defined

 Numeric---------------

1. int=1,2,3

2. float=1.2,3.4

3. complex=3+5j

4. bool(boolean) = bool=b<k, it gives true or false

*if only the int part of a variable is to be used then use int(variable)

*to convert int into floatt type, use float(variable)

*to convert any no. into complex form , use complex(variable)

 lists

 tuple

 set

 string

 range---reprentation= range(10)=(0,10)

*to print the elements of range , use lists(range(10))

 dictionary-----------
In dictionary , an element is represented by its key
Page 5 of 5

d={‘ashish’:’honor’,’abhay’:’samsung’}
d[‘ashish’]=’honor’ or d.get(‘ashish’)=’honor’
d.keys=({‘ashish’,’abhay’})
d.values=({‘honor’,’samsung’})
*we use curley brackets in dictionary because the keys cannot be same and we know
that the elements of sets donot repeat.

15. Functions used for number system conversion:--------

a) bin function = used to covert decimal into binary


bin(12)=0b1100
*here 0b is used to specify that the given no. is in binary format.
If a binary no. is to be converted into decimal then , simply type 0b1100 and the
output will be 12
b) oct function = used to convert decimal into octal
oct(25)=0o31 , where 0o represents that the given no. is in octal format
c) hex function = used to convert decimal into hexadecimal
hex(25)=0x19 , where 0x represents hexadecimal

You might also like