Python 3 detect and prevent TypeError-s

preview_player
Показать описание
Python detect and prevent TypeError: sequence item 0 and join iterable

Errors:

* TypeError: sequence item 0: expected str instance, int found

and

* TypeError: can only join an iterable

Option 1

import collections
mylist = 2
if isinstance(mylist, collections.Iterable):
print(', '.join(mylist))

Option 2

try:
iterator = iter(mylist)
except TypeError:
print('not iterable')
else:
print(', '.join(mylist))
Рекомендации по теме
Комментарии
Автор

hello bro one more small request i have school project and i am stuck at it
you helped me with one off my question if you will please help me with this last question too please please please bro


Question: : Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐ a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use self keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.

HIGHLIGHTS.TV-FOOTBALL
join shbcf.ru