String or Number?
Strings are surrounded by quotes. If anything has quotes surrounding it, it’s a string. For example:
x = '5'might make you believe that x equals to 5, but it isn’t. If you were to reference it, the code would treat it as a string and not a number, so you wouldn’t be able to add it or do any types of math.
# strings x = '5' y = '6' print(x + y) # this is 56 (concatentation) # integers a = 5 b = 6 print(a + b) # this is 11 (addition)
View code on GitHub.
Print Data Types
Practice: Come up with 3 examples each of floating numbers, integers, and strings and print them.
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact firstname.lastname@example.org for inquiries.