programming, java, software, PHP, C programming, programming languages, visual, Pascal, Perl, XML program, UNIX, cyber program, C++, HTML, CSS, Python syntax, software, what is computer, programming, programming languages, computer programming, what is coding, what is programming, contract programming, need a programmer, cyber program, tmbmnadim, Alpha Codist, python
Python syntax 2
Name of syntax
|
What it does
|
Example
|
Execute
|
Creating a loop
|
for a word in "Alpha Codist":
print(word)
|
A
l
p
h
a
C
o
d
i
s
t
|
|
To create a list
|
d = [1, 4, 'Alpha', 'Codist']
print(d)
|
[1, 4, 'Alpha', 'Codist']
|
|
d = [1, 4, 'Alpha', 'Codist']
for items in d:
print(items)
|
1
4
Alpha
Codist
|
||
nameofliist.append()
|
Adds item on list in last
|
e = [1, 4, 'Alpha', 'Codist']
e.append('is the best')
print(e)
|
[1, 4, 'Alpha', 'Codist', 'is the best']
|
nameofliist.insert(where you want, what you want)
|
Adds item anywhere on list
|
f = [1, 4, 'Alpha', 'Is the best']
f.insert(3, 'Codist')
print(f)
|
[1, 4, 'Alpha', 'Codist', 'Is the best']
|
nameofliist.remove()
|
Removes item from list
|
g = [1, 4, 'Alpha', 'Codist', 'Is the best']
g.remove(1)
print(g)
|
[4, 'Alpha', 'Codist', 'Is the best']
|
nameofliist.clear()
|
Clears the whole list
|
h = [1, 4, 'Alpha', 'Codist', 'Is the best']
h.clear()
print(h)
|
[]
|
nameofliist.pop()
|
Removes the last item from the list
|
i = [1, 4, 'Alpha', 'Codist', 'Is the best']
i.pop()
print(i)
|
[1, 4, 'Alpha', 'Codist']
|
nameofliist.index(the item you want to check)
|
Checks items index
|
j = [1, 4, 'Alpha', 'Codist', 'Is the best']
j.index('Alpha')
print(j)
|
2(The index of ‘Alpha’)
|
k = [1, 4, 'Alpha', 'Codist', 'Is the best']
k.index(5)
print(k)
|
ValueError: 5 is not in list
|
||
Print(Youritem In listnumber)
|
Checks if the item is in the list
|
l = [1, 4, 'Alpha', 'Codist', 'Is the best']
print(5 in l)
|
False
|
nameofliist.count()
|
To count occurrences of item
|
m = [1, 4, 'Alpha', 'Codist', 'Alpha', 'Is the best']
print(m.count('Alpha'))
|
2
|
COMMENTS