how to declare type in python code example
Example 1: python declare int
x = 5
print(type(x))
# Output: <class 'int'>
Example 2: declare float python
myfloat = 7.0
Example 3: type declaration python
def greeting(name: str) -> str:
return 'Hello ' + name
Example 4: type in python
numbers_list = [1, 2]
print(type(numbers_list))
numbers_dict = {1: 'one', 2: 'two'}
print(type(numbers_dict))
class Foo:
a = 0
foo = Foo()
print(type(foo))
Output
<class 'dict'>
<class 'Foo'>
<class '__main__.Foo'>