
You can assign the same value to multiple variables by using = consecutively.
This is useful, for example, when initializing multiple variables to the same value.
a = b = c =100
print(a)
# 100
print(b,c)
# 100 100
You can assign the same value to multiple variables by using = consecutively.
This is useful, for example, when initializing multiple variables to the same value.
a = b = c =100
print(a)
# 100
print(b,c)
# 100 100
The underscore (_)is used to retrieve the result of the last expression executed in the command line interface.
>>> num 1= 10
>>> num2= 20
>>> num1 + num2
30
>>> num3 = _ +10
>>> num3
40
When you enter string literals separated by a space, Python concatenates them
As a result, ‘Hello World’ becomes ‘HelloWorld’.
print(“Hello” “world”)
Output: Helloworld
You can assign multiple values to multiple variables by separating variables and values with commas ,
.
a,b,c,d,e = 1,2,3,4,5
print(a,b,c,d,e)
Output: 1 2 3 4 5
Python supports multiple returns from a single function which is not possible in most of the modern day programming languages
def example():
Return ‘abc’, 10
print(example())
print(example())
Output:
(‘abc’, 10)
(‘abc’, 10)
RANK | PROGRAMMING LANGUAGES | MARKET SHARE |
1 | PYTHON | 29.48% |
2 | JAVA | 17.18% |
3 | JAVASCRIPT | 9.14% |
4 | C# | 6.94% |
5 | PHP | 6.49% |
6 | C/C++ | 6.49% |
7 | R | 3.59% |
8 | TYPE SCRIPT | 2.18% |
9 | SWIFT | 2.1% |
10 | OBJECTIVE | 2.06% |