In this video we will see how to run python programs in MS Visual Studio Code. Please watch this video and let me know in the comments section if you have any questions. Please do like, share and subscribe my youtube channel for more such videos. https://www.youtube.com/watch?v=iW1VHVXCILA Cheet Sheet: 👇 Type Casting What is type casting? Type casting, on a very basic level, is the method involved with changing the information kind of a variable. v Fuction used in type casting: int(): Converts a worth to a whole number. float(): Converts a worth to a drifting point number. str(): Converts a worth to a string. bool(): Converts a worth to a boolean. v Examples of implicit type casting: program1: a = 2.5 b = 3 + 4j result = a + b print(result) program2: num = 10 message = "The value of num is: " + str(num) print(message) Examples of explicit type casting: Program1: num_float = 3.1...
Python string is the collection of the characters surrounded by single quotes, double quotes, or triple quotes. #Using single quotes str1 = 'Hello Python' print(str1) #Using double quotes str2 = "Hello Python" print(str2) #Using triple quotes str3 = '''''Triple quotes are generally used for represent the multiline or docstring''' print(str3) String Indexing # Given String str = "PYTHONSTRING" # Start Oth index to end print(str[0:]) # Starts 1th index to 4th index print(str[1:5]) # Starts 2nd index to 3rd index print(str[2:4]) # Starts 0th to 2nd index print(str[:3]) #Starts 4th to 6th index print(str[4:7]) str = 'PYTHONSTRING' print(str[-1]) print(str[-3]) print(str[-2:]) print(str[-4:-1]) print(str[-7:-2]) # Reversing the given string print(str[::-1]) print(str[-12]) Reassigning Strings str = "HELLO" str[0] = "h" print(str) str = "HELLO...
2 Types of loops in python: 1) For Loop: It is designed to repeatedly execute a code block while iterating through a list, tuple, dictionary, or other iterable objects of Python. string = "Python" # Initiating a loop for s in a string: # giving a condition in if block if s == "o": print("If block") # if condition is not satisfied then else block will be executed else: print(s) ---------------------------------------------------------------------------------------------------------------------------- numbers = [3, 5, 23, 6, 5, 1, 2, 9, 8] # initializing a variable that will store the sum sum_ = 0 # using for loop to iterate over the list for num in numbers: sum_ = sum_ + num ** 2 print("The sum of squares is: ", sum_) ----------------------------------------------------------------------------------------------------------------------------- my_list = [3, 5, 6, 8, 4] for iter_var in ra...
Comments
Post a Comment
Please comment