# Working with Variables # Create the following variables: # 2 strings named string1 and string2. string1 should equal '7' and string2 should equal '8' # 1 int named int1 that contains 7 # 1 floats named float2 that contains 8 # Remember that in order to create a variable we have to supply a name and a data type # we supply the data type by giving the variable a piece of data so the syntax is: # variable_name = piece_of_data # Uncomment the line below and run the program. What result do you get? Why? Answer: # Be sure to recomment the line after you answer the question # print(string1+string2) # Uncomment the line below and run the program. What result do you get? Why? Answer: # print(string1 + int1) # Uncomment the line below and run the program. What result do you get? Why? Answer: # print(float2 + int1) # We can use the type function to determine the type that is returned from a statement # The line below takes advantage of what we learned about strings in the first print statement # notice how we can use that knowledge to our advantage to create better prints. # Note: in our editor and in python3 we separate statements with a + sign, in Python Fiddle # we have to use a , to separate them. The comma is not standard and we will use the + when we # work on our projects. # print("Float2 equals" , float2) # What function can we use in python to always know a variables data type? Answer:
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question