3️⃣

2.3 String or Number?

 

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.
 
Example code:
# 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.

Practice

Print Data Types

Practice: Come up with 3 examples each of floating numbers, integers, and strings and print them.

Previous Section

2️⃣
2.2 Variables

Next Section

4️⃣
2.4 Casting
 
⚖️
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 classes@code4tomorrow.org for inquiries.