Tuesday, November 26, 2019

single value Tuple in python

If we indicate the parenthesis with single value  then that should not be considered as tuple .

example 1:

t=(10)
print(type(t))
print(t)

output:
<class 'int'>
10

example 2:
t=('A')
print(type(t))

print(t)

output:
<class 'str'>
A

single value tuple indicates as (first value,)

example 3:
t=(10)
print(type(t))
print(t)
t=('A')
print(type(t))
print(t)
t=(10,)
print(type(t))

print(t)

output:
<class 'int'>
10
<class 'str'>
A
<class 'tuple'>
(10,)


No comments:

Post a Comment

python class topic video