“Python -Liste” Code-Antworten

Python -Liste

python_list = [1, 2, 3, 4, 5]
Outrageous Ostrich

Python -Liste

my_list = [1, 2, '3', True]# We assume this list won't mutate for each example below
len(my_list)               # 4
my_list.index('3')         # 2
my_list.count(2)           # 1 --> count how many times 2 appears

my_list[3]                 # True
my_list[1:]                # [2, '3', True]
my_list[:1]                # [1]
my_list[-1]                # True
my_list[::1]               # [1, 2, '3', True]
my_list[::-1]              # [True, '3', 2, 1]
my_list[0:3:2]             # [1, '3']

# : is called slicing and has the format [ start : end : step ]
Tejas Naik

Python -Liste

a1 = [1, 'x', 'y']
a2 = [1, 'x', 'y']
a3 = [1, 'x', 'y']

b = [2, 3]

a1.append(b)
a2.insert(3, b)
a3.extend(b)

print(a1)
print(a2)
print(a3
futurespoir

Python -Liste

list1 = [10, 20, 4, 45, 99]
 
mx=max(list1[0],list1[1])
secondmax=min(list1[0],list1[1])
n =len(list1)
for i in range(2,n):
    if list1[i]>mx:
        secondmax=mx
        mx=list1[i]
    elif list1[i]>secondmax and \
        mx != list1[i]:
        secondmax=list1[i]
 
print("Second highest number is : ",\
      str(secondmax))
      
 Output:-     
      
Second highest number is :  45
CodeExampler

Python -Liste

list_name = [list_item1, list_item2, ...]
alimehridev

Python -Liste

# a list of programming languages
['Python', 'C++', 'JavaScript']
SAMER SAEID

Python -Liste

a[2] =  15
a[0:3] =  [5, 10, 15]
a[5:] =  [30, 35, 40]
Lenka Skalová

Python -Liste

for x in term:
Frantic Flat342

Ähnliche Antworten wie “Python -Liste”

Fragen ähnlich wie “Python -Liste”

Weitere verwandte Antworten zu “Python -Liste” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen