Skip to main content

Posts

Showing posts with the label Python Variables

Python For Beginners - Python Variables & Comments

Python Variables In Python, variables are used to store data values. A variable can hold different types of data, such as numbers, strings, or booleans. Here's an example of how to create and use variables in Python: # Integer variable num1 = 5 num2 = 10 sum = num1 + num2 print(sum)  # Output: 15 # String variable name = "John" print("My name is " + name)  # Output: My name is John # Boolean variable is_sunny = True if is_sunny:     print("It's a sunny day!")  # Output: It's a sunny day! else:     print("It's a cloudy day.") In the above example, we first create two integer variables num1 and num2, then we create a variable called sum which holds the sum of num1 and num2. We then print the value of sum using the print() function. Next, we create a string variable name and concatenate it with a string literal using the + operator. Finally, we create a boolean variable is sunny and use it in an if-else statement to print whether it...