Python Fundamentals for Non - Programmers
Python Fundamentals for Non - Programmers
In [2]: employee_name
Out[2]: "'vismit'"
Out[6]: "'nandan'"
In [7]: employee_name
Out[7]: "'nandan'"
Out[11]: 'vinil'
Out[16]: 'vismit'
Out[17]: 3.88
In [18]: type(data_type)
Out[18]: float
Out[19]: "'23'"
In [20]: type(data_type2)
Out[20]: str
In [21]: type(employee_name)
Out[21]: str
In [22]: data_type3 = 88
data_type3
Out[22]: 88
In [23]: type(data_type3)
Out[23]: int
Out[28]: True
In [29]: type(data_type5)
Out[29]: bool
In [30]: a1 = 80+2843j
a1
Out[30]: (80+2843j)
In [31]: type(a1)
Out[31]: complex
In [33]: a=60
b=20
#+,-,*,/ (all arthematic operators)
In [34]: a+b
Out[34]: 80
In [35]: a-b
Out[35]: 40
In [36]: b-a
Out[36]: -40
In [37]: a*b
Out[37]: 1200
In [38]: a/b
Out[38]: 3.0
data_type6 = <class 'int'> data_type7 = <class 'float'> -hence , we can conclude that 3 is an i
nt data type and 3.0 is an float data type
Out[60]: True
In [61]: a<b
Out[61]: False
In [62]: a==b
Out[62]: False
In [63]: a!=b
Out[63]: True
In [64]: #if
a1=100
a2=100
#then
a1==a2
Out[64]: True
In [65]: # Logical Operatiors & , | (press shift + \ this type hash button above enter button)
In [67]: a=True
b=False
In [69]: a&b
Out[69]: False
In [70]: b&a
Out[70]: False
In [71]: b&b
Out[71]: False
In [72]: a&a
Out[72]: True
In [73]: a|b
Out[73]: True
In [75]: b|a
Out[75]: True
In [76]: b|b
Out[76]: False
In [77]: a|a
Out[77]: True
In [85]: a[0]
Out[85]: 'h'
In [86]: a[3]
Out[86]: 'l'
In [87]: a[-1]
Out[87]: 'd'
In [88]: a[-0]
Out[88]: 'h'
In [89]: a[-2]
Out[89]: 'l'
In [90]: a[5]
In [91]: a[10]
Out[91]: 'd'
In [92]: a[-1]
Out[92]: 'd'
In [93]: a[-10]
Out[93]: 'e'
In [94]: a[-11]
Out[94]: 'h'
In [101… a[3:9]
Out[101]: 'people'
In [109… a[-5:23]
Out[109]: 'human'
In [111… len(a)
Out[111]: 21
In [113… a[-21]
Out[113]: 'h'
In [114… a.upper()
In [118… a
In [124… a
In [125… a.count('p')
Out[125]: 2
In [126… a
In [141… a.find('human')
Out[141]: 20
In [147… a.find('m')
Out[147]: 14
In [130… a[10:13]
Out[130]: 'iam'
In [131… a
In [133… a
In [136… a= 'hi people % iam a % human' #you can use any symbol to split examples used here = . & %
a.split('%')
In [2]: a = 'hi'
a.replace('hi',"hey")
Out[2]: 'hey'
In [3]: a.count('hi')
Out[3]: 1
In [4]: a.count('i')
Out[4]: 1
In [5]: a.count("h")
Out[5]: 1
In [6]: a[0:1]
Out[6]: 'h'
In [7]: a[0:2]
Out[7]: 'hi'
In [11]: a.count('n') #count function is to find how many time the letter or albhabet is repeated
Out[11]: 1
Out[12]: 6
In [13]: #Concept Tuples ( a type of data structure ) (tuples are immutable or the values inside it ca
#NOTE = the major difference in assigining lists and tuples are :
# IN LIST we use square brackets [] to assign values
# BUT in TUPLES we use round brackets () to assign values .
# eg, list = [1,2,3]
# tuple = (1,2,3)
In [57]: tuple1
In [24]: type(tuple1)
Out[24]: tuple
In [63]: tuple1[-1]
Out[63]: 3.14
In [58]: tuple1[-2]
Out[58]: True
In [59]: tuple1[:]
In [30]: tuple1
In [60]: tuple1[2]
Out[60]: True
In [61]: tuple1[3]
Out[61]: 3.14
In [62]: tuple1.replace ('hello','jet') #tuples are immutable (cant be changed once assigned)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[62], line 1
----> 1 tuple1.replace ('hello','jet')
In [48]: a = 'hi'
Out[50]: 'hey'
In [67]: tuple2+tuple3
Out[67]: (88,
'hey',
(34+5j),
False,
8,
'op',
(70+45634232j),
3.5623323323,
True,
True,
'feeadfqqdefwevwfadvwdqcwewdawdwfc you need not to understand lol ')
In [68]: tuple1+tuple3
Out[68]: (1,
'hello',
True,
3.14,
8,
'op',
(70+45634232j),
3.5623323323,
True,
True,
'feeadfqqdefwevwfadvwdqcwewdawdwfc you need not to understand lol ')
In [69]: tuple2+tuple1
In [70]: #repeating the elements in tuple agian and agian how much times we want
In [72]: tuple4
In [74]: tuple4*2
In [77]: tuple1
In [78]: tuple4
Out[79]: (8, 'hi', True, 8, 'hi', True, 8, 'hi', True, 1, 'hello', True, 3.14)
In [80]: # to find the minimum or smallest number value of tuple and maximum or largest number pre
#remember its just for finding largest and smallest number dosent apply for letters in tuple.
In [86]: min(tuple4)
Out[86]: -32
In [87]: max(tuple4) #hence here min number is -32 and max number is 556
Out[87]: 556
In [88]: #concept LISTS they are mutable or can change values in it. ( a type of data structure )
#NOTE = the major difference in assigining lists and tuples are :
# IN LIST we use square brackets [] to assign values
# BUT in TUPLES we use round brackets () to assign values .
# eg, list = [1,2,3]
# tuple = (1,2,3)
In [175… type(list1)
Out[175]: list
In [176… list1
In [177… list1[1]
Out[177]: 'hey'
In [178… list1[0]
Out[178]: 8
In [179… list1[1:4]
In [180… #changing the values inside list as lists are mutable or changable.
In [181… list1
In [183… list1
In [186… list1
Out[186]: [8, 'hey', 'hello people', (3+5j), 'ok bye bye ']
In [188… list1.pop()
In [189… list1 #here in the output the last emelment (which was ok bye bye) is popped or removed ou
In [190… list1.pop(2)
In [191… list1
In [193… list1
In [194… list1.reverse()
list1
In [196… list1
In [198… list1 #type the index number of element in which u have to insert the new element and the g
In [201… list2
In [202… list2.sort()
In [203… list2
In [205… list1
In [206… list2
In [207… list1+list2
In [208… list2+list1
In [212… list2*3
Out[212]: ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd']
In [213… list2*2+list1
Out[213]: ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', (3+5j), 'hey', True, 8]
In [215… # dictonary can be assigned any name for ex fruits , cars , bikes ,foods .
#means it is having the specific category like fruit dictonary have set of fruits like apple orrang
In [1]: fruit = {'apple':30, 'banana':50} #here 30 and 50 are cost or number of apple and b
In [2]: #here the apple and banana (the alphabets ) is called as KEYS of dictonary .
# And 30 and 50 (the numbers) are called as values of dictonary.
In [3]: fruit
In [4]: type(fruit)
Out[4]: dict
In [5]: #to extract only keys or alphabets of the dictonary called fruits
In [6]: fruit
In [7]: fruit.keys()
In [9]: fruit
In [10]: fruit.values()
In [12]: fruit
In [13]: fruit.items()
In [14]: #to add a new item in dictonary (an item consists of a key and value )
In [15]: fruit
In [18]: fruit['mango'] = 40
In [19]: fruit
In [21]: fruit['apple']= 80
In [22]: fruit
In [23]: #to add a new set of items into a dictonary from another dictonary or to merge the items in a
In [24]: fruit
In [32]: fruit
In [33]: specialfruit
In [34]: fruit.update(specialfruit)
In [35]: fruit #hence the special fruit dictonary is added to a single dictonary named fruit .
Out[35]: {'apple': 80, 'banana': 50, 'mango': 40, 'watermelon': 45, 'musk melon': 28}
In [36]: # to pop or remove an item from dictonary. (item is a collection of a key [alphabet] and a
In [37]: fruit
Out[37]: {'apple': 80, 'banana': 50, 'mango': 40, 'watermelon': 45, 'musk melon': 28}
In [38]: fruit.pop("banana")
Out[38]: 50
In [39]: fruit #hence, here the banana item is been removed from dictonary .
Out[39]: {'apple': 80, 'mango': 40, 'watermelon': 45, 'musk melon': 28}
In [40]: # concept SET ( a type of data structure ) (sets are MUTABLE or can change values inside
# set is a unordered and unindexed (the single elements dosent have its specific place or num
# we use curly brackets {} to assign a set .
# NOTE : in dictonary also we use curly brackets but there we have a key (word) and a value
# - ents present in set
# no elements can be repeated twice in set . (there should not be the same number or word a
In [74]: set1 = {1,'hi','hi',6} # ex here in the set i hve repeated hi 2 times but in output it came only onc
set1
In [76]: set1
In [77]: set1.add("ok")
set1
In [79]: set1
In [80]: set1.remove("hi")
set1
In [82]: set1
In [83]: set1.update(['hello']) # note : seee output u cant even repeat letters in a set .
# In set for updating u shd use both round and square brackets ([
set1 #if u dont use both brackets it comes like {}'h','e','l','o', } if u use it c
In [86]: set3
Out[86]: {1, 2, 3, 4}
In [87]: set4
Out[87]: {3, 4, 5, 6}
In [88]: set3.union(set4)
Out[88]: {1, 2, 3, 4, 5, 6}
In [90]: set3
Out[90]: {1, 2, 3, 4}
In [91]: set4
Out[91]: {3, 4, 5, 6}
In [92]: set3.intersection(set4)
Out[92]: {3, 4}
In [ ]: