Professional Documents
Culture Documents
Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python
In the previous ar ticle, we read about the basic s of P ython. Now, we continue with
Strings in P ython:
and special characters. It can be declared in python by using single quotes, double
quotes, or even triple quotes. These quotes are not a par t of a string, they define only
star ting and ending of the string. Strings are immutable, i.e., they cannot be
changed. Each element of the string can be accessed using indexing or slicing
operations.
0:00 to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
We use cookies
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 1/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Output :
This is a string
This is a string
This is a string
Lists in P ython:
Lists are one of the most power ful data structures in python. Lists are sequenced
data types. In P ython, an empty list is created using list() function. They are just like
the arrays declared in other languages. But the most power ful thing is that list need
not be always homogeneous. A single list can contain strings, integers, as well as
other objects. Lists can also be used for implementing stacks and queues. Lists are
mutable, i.e., they can be altered once declared. The elements of list can be accessed
P ython
# Declaring a list
L = [1, "a" , "string" , 1+2]
print L
#Adding an element in the list
L.append(6)
print L
#Deleting last element from a list
L.pop()
print L
#Displaying Second element of the list
print L[1]
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 2/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Login Register
[1, 'a', 'string', 3]
Tuples in P ython: A tuple is a sequence of immutable P ython objects. Tuples are just
like lists with the exception that tuples cannot be changed once declared. Tuples are
P ython
The output is :
Iterations in P ython: Iterations or looping can be per formed in python by ‘for ’ and
‘while’ loops. Apar t from iterating upon a par ticular condition, we can also iterate on
P ython
i = 1
while (i < 10):
print(i)
i += 1
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
1
Got It !
3
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 3/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Start
5
Your Coding Journey Now! Login Register
6
P ython
s = "Hello World"
for i in s:
print(i)
P ython
L = [1, 4, 5, 7, 8, 9]
for i in L:
print(i)
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
The output is:
Got It !
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 4/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Start
1
P ython
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
Like 219
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 5/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Previous Next
Ar ticle Contributed By :
GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
Vote for difficulty that you have read and understood our
Cookie Policy &
Privacy Policy
Current difficulty :
Easy
Got It !
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 6/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
Load Comments
feedback@geeksforgeeks.org
Company Learn
About Us Algorithms
Careers Data Structures
In Media SDE Cheat Sheet
Contact Us Machine learning
Privacy Policy CS Subjects
Copyright Policy Video Tutorials
Courses
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
Languages
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 7/8
7/27/22, 9:42 AM Python | Set 3 (Strings, Lists, Tuples, Iterations) - GeeksforGeeks
News Python
Start Your Coding Journey Now! Login
Java
Register
Top News
CPP
Technology
Golang
Work & Career
C#
Business
SQL
Finance
Kotlin
Lifestyle
Knowledge
@geeksforgeeks
, Some rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge
that you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/python-set-3-strings-lists-tuples-iterations/?ref=lbp 8/8