Assigning Values to Variables:
Python variables do NOT need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. Every variable in Python is an object. Let's take a look of the following example.
car = 100 # An integer assignment
miles = 1000.37 # A floating point
name = "John" # A string, remember that for string, we used ""
print (car)
print (miles)
print (name)
miles = 1000.37 # A floating point
name = "John" # A string, remember that for string, we used ""
print (miles)
print (name)
In python shell you will see following output,
Python Strings:
String in Python is identified as a contiguous set of characters represented in the quotation marks. One can use single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string.
# Let's talk about strings
print (str) # Prints complete string
print (str[0]) # Prints first character of the string
print (str[3:6]) # Prints characters starting from 4th to 6th
print (str[3:]) # Prints string starting from 4th character
print (str * 2) # Prints string two times
print ("You are, "+ str) # Prints concatenated string
str = "Welcome to Learn Python!"
print (str[0]) # Prints first character of the string
print (str[3:6]) # Prints characters starting from 4th to 6th
print (str[3:]) # Prints string starting from 4th character
print (str * 2) # Prints string two times
print ("You are, "+ str) # Prints concatenated string