Home > other >  Python beginners to solve, bosses give directions
Python beginners to solve, bosses give directions

Time:09-19

>> X=[10] [0] + 1
11.
Version pthon3.5.0, Windows 7
Want to know why is equal to 11, [10] [0] is interpreted as a list or dictionary, how to calculate, shoot shoot bosses

CodePudding user response:

[10] is list in which there is only one element of 10
[10] [0] said to take the first element in a list [10], is 10
The 10 + 1=11

CodePudding user response:

 x=[10] 
Print (' is the value of x, x, 'type, type (x),' length, len (x))
X=[10] [0]
Print (' is the value of x, x, 'type, type (x))
# print (' length 'len (x)) # type int no len ()
X=[10] [0] + 1
Print (' is the value of x, x, 'type, type (x))

The value of x is [10] type & lt; The class 'list' & gt; The length of 1
The value of x is 10 types & lt; The class 'int' & gt;
The value of x is 11 types & lt; The class 'int' & gt;

CodePudding user response:

The first is the 10 list elements
  • Related