Errors! - Introduction to Python: Absolute Beginner Module 1 Video 12

Опубликовано: 12 Июль 2021
на канале: Book Simplifiers
25
2

Example
[ ] review & run code
print("my number is " + "123") #string, represents a text character
print("my number is " + 123) #number, with numeric value
TypeError
The line print("my number is " + 123) causes the TypeError message to appear

TypeError: Can't convert 'int' object to str implicitly

When adding to the string "my number is " the compiler is experiencing another string, but finds a number *123

Python cannot convert the Integer 123 to a string without explicit instruction (in code)

in other words, python only allows combining like types

str + str
int + int
Task 3
Fix TypeError
Review the code in the cells below and then run the code
Fix any errors and run until the code no longer shows errors
[ ] review and run the code - then fix any Errors
total_cost = 3 + "45"
print(total_cost)

[ ] review and run the code - then fix any Errors
school_num = 123
print("the street number of Central School is " + school_num)

[ ] Read and run the code - write a hypothesis for what you observe adding float + int
[ ] HYPOTHESIS:

print(type(3.3))
print(type(3))
print(3.3 + 3)


На этой странице сайта вы можете посмотреть видео онлайн Errors! - Introduction to Python: Absolute Beginner Module 1 Video 12 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Book Simplifiers 12 Июль 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 25 раз и оно понравилось 2 зрителям. Приятного просмотра!