Posts

Showing posts from January, 2022

Lists [ ]

  #Lists #what is a list - List is ordered and changeable data type, It is used to store multiple values in a single variable. list1  = [ 1 , 2 , 3 , "rakesh" ] list2 = [ "Jabalpur" , 30.50 , "Khalsa" ] print ( list1 ) print ( list2 ) #access the elements print ( list1 [ 2 ]) print ( list2 [- 2 ]) #Negative Indexing #slicing - is also called segment print ( list1 [ 1 : 3 ]) print ( list2 [:- 2 ]) if "Jabalpur" in list2 :       print ( "Yes jabalpur is in the list2" ) #Change elements #using index number list1 [ 3 ] = "suresh" print ( list1 ) #rakesh will be replaced with suresh list1 [ 4 ] = "suresh" print ( list1 ) # Error- Index Out of Range #Change the element using slicing list1 [ 0 : 3 ] = [ 101 , "MCA" ] print ( list1 ) #delete the last element print ( list1 . pop ()) print ( list1 ) #insert the element at position 2 print ( list1 . insert ( 2 , "rakesh" )) print ( list1 ) #remove the e...

String

  # what is a data type # data type is used to express the type of variable. # str is a type used for text. # int,float and complex are the types for number # bool is a type for boolean values # Type-Casting # typecast integer to string a = 10 b = str ( a ) print ( b ) print ( type ( b )) #we can check the type of variable #typecast string to integer c = "10" d = int ( c ) print ( d ) print ( type ( d )) #String #String is a type str1 = "ChiTRAnsh " str2 = "thakur" str3 = str1 + str2 print ( str3 ) print ( len ( str3 )) #String is an array of characters. print ( str1 [ 3 ]) #we can access the element using index number #looping for x in str2 :       print ( x ) #slicing print ( str1 [ 3 : 9 ]) #modify strings print ( str1 ) print ( str1 . upper ()) print ( str1 . lower ()) print ( str1 . capitalize ()) #strip() - strip() is used to remove the whitespaces from begining or end. str5 = " chitransh thakur " print ( str5 . strip ())   #spl...

Data Types & Type Casting

# what is a data type # data type is used to express the type of variable. # str is a type used for text. # int,float and complex are the types for number # bool is a type for boolean values # Type-Casting # typecast integer to string a = 10 b = str ( a ) print ( b ) print ( type ( b )) #we can check the type of variable #typecast string to integer c = "10" d = int ( c ) print ( d ) print ( type ( d ))  

Python Basics & Variables

Python-  Python is a high level programming language.  Python is scripting language. It is an interpreted language. It is easy to use. What is Scripting Language:-  Scripting Language is a language where we create scripts(series of commands) and those scripts are interpreted only in runtime. What is Interpreted language:-  Interpreted language that checks the error line by line and shows it during the writing of program. # Printing the statements  print("Helloworld!!") #Multiple words variables?? camelCase, PascalCase, snake_case -> snake_case is recommended. #Assigning multiple variables x,y,z = "Anna","Bhawa","Chandra" friends = [] friends = x,y,z  print(friends) #Output ["Anna","Bhawa","Chandra"] #Variables Play a = "Ashish" b = 10 print(a+b) #Not Possible, Two values with same data type can only be added. #Global Variable Variables that are created outside the function is called global variables. gl...