- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Interesting facts about strings in Python
In this article, we will learn about some Interesting facts about strings in Python 3.x. Or earlier.
- Immutability
- Auto-detection of escape sequences
- Direct slicing
- Indexed access
Immutability
This means that there is no permission of modification on <string>type and we only have read only access to the strings.
Example
inp = 'Tutorials point' # output print(inp) # assigning a new value to a particular index in a string inp[0] = 't' print(inp) # raises an error
Output
TypeError: 'str' object does not support item assignment
Auto-detection of escape sequences
The strings containing backslash are automatically detected as an escape sequence.
Example
inp = 'Tutorials point' # output print(inp+”\n”+”101”)
Output
Tutorials point 101
Direct slicing
We all are aware of substring method in c or c+ +, Slicing does the same operation in python. it takes two compulsory and 1 optional argument. Compulsory arguments are start index (included) and end index(not included) Optional argument is the step or say increment or decement value. By default it is 1.
Example
inp = 'Tutorials point' # output print(inp[0:5])
Output
Tutor
Indexed access
As all elements are stored in a contiguous format, therefore we can access elements directly by the help of index.
Example
inp = 'Tutorials point' # output print(inp[0]+inp[1])
Output
Tu
Conclusion
In this article, we learnt about Interesting facts about strings in Python 3.x. Or earlier.
- Related Articles
- Interesting Facts about Java
- Interesting Facts about C Programming
- Interesting facts about null in Java
- Interesting facts about Array assignment in Java
- What are some interesting facts about space?
- What are some interesting facts about humans?
- What are the interesting facts about Computer Viruses?
- Interesting facts about Increment and Decrement operators in Java
- What are the interesting facts about the Nobel Prize?
- C++ bitset interesting facts?
- Who built the golden temple and what are some interesting facts about it?
- What are some interesting facts about World War 1 that aren't widely known?
- What are the interesting facts of the Star Wars theme parks?
- 10 Surprising Facts about the Human Brain
- What are some unknown facts about our body?
