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

Python

Uploaded by

bhotosooty
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python

Uploaded by

bhotosooty
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

basic functions:-

===============
==>type(data)--it is a function used to find the data type of a data in a variable.
==>len(string)--it is a function used to get the length of string or collections
==> del -- it is a keyword in python used to delete data from memory ex:- del
list1.
==>input("message")--it is a function used to the user input.it return type is
always string.
==>type casting:-converting one type of data to another type of data
-->int("int value")--used to convert the string of int value to int.
-->float("float value")--used to convert the string of float value to float.
-->bool("bool value")--used to convert the string of bool value to bool.

data Strucures:-
===============

1.list:-
-------
--> it can caontain hetregeneous
--> indexed /ordered
--> allows negative index
--> mutable
--> allow duplicates
--> [] are used to create list
--> methods -len(list_name),pop(index)-delete the index item,remove(value/item)-
delete the given item(first occurred) , list.append(item)-to add item at last of
list
list.insert(index,item)-add the item at given index.
--> slice-- list[start_ind:end_position], list[:]-gives full list,list[st_ind:]-
give items from given st_index to end of list, list[:end_ind]-gives from starting
index to given end_index.
--> list.clear()-- used to clear the all items in list.

2.Tuple:-
------------
--> it contains only homogeneous elements
--> immutable
--> it allows duplicates.
--> allows indexing
--> () are used to create tuple.
--> to create single itemvtuple , is needed.ex:- t1=("lokesh",)

3.Dictionary:-
-----------------
--> hetregenous
--> {} are used to create dictionary.
--> stores data in key:value pair
--> duplicate keys are not allowed but values allowed.
--> keys are used to access the values/there is no indexing.
--> mutable
--> create dictionary :-
dict1={"name":"lokesh","age":20,"pass":True,False:"zero",30:"hero"}
--> keys must be String,int,float,bool,Tuple
--> values can be anything..
--> methods--dict.keys()-returns the list of all keys,dict.values()-return the list
of all values,dict.items()-returns all key value pairs in the form of Tuple.
--> access :- print(dict["name"]) o/p:- "lokesh"
--> re-assign :- dict1["age"]=22
print(dict1["age"]) o/p :- 22
ex:- for key in dict1.keys():
print(key,dict1[key],sep=" : ")
--> remove item -- dict1.pop("name")
-- del dict1["age"]
--> dict.clear()-- used to clear the all items in dictionary.

4.Set :-
---------
--> Heterogenous element.
--> Unordered
--> immutable / but able to add new items
--> {} are used to create set
--> doesn't duplicates
--> to create empty set ex:- s1= set()
--> functions -- set.add()-used to add the items to set.
--> set1.update(set2) -- this add the set2 items in set1.
--> set1.union(set2) -- this generates and return new set with the elements in both
sets(old sets are not updated).
--> set1.intersection(s2) -- returns the commom items in both sets
--> set1.symmetric_difference(set2) -- returns the not common items

set1={"lokesh",143,"heroine",True}
for item in set1:
print(item)

You might also like