Categories
5G Network
Agile
Amazon EC2
Android
Angular
Ansible
Arduino
Artificial Intelligence
Augmented Reality
AWS
Azure
Big Data
Blockchain
BootStrap
Cache Teachniques
Cassandra
Commercial Insurance
C#
C++
Cloud
CD
CI
Cyber Security
Data Handling
Data using R
Data Science
DBMS
Design-Pattern
DevOps
ECMAScript
Fortify
Ethical Hacking
Framework
GIT
GIT Slack
Gradle
Hadoop
HBase
HDFS
Hibernate
Hive
HTML
Image Processing
IOT
JavaScript
Java
Jenkins
Jira
JUnit
Kibana
Linux
Machine Learning
MangoDB
MVC
NGINX
Onsen UI
Oracle
PHP
Python
QTP
R Language
Regression Analysis
React JS
Robotic
Salesforce
SAP
Selenium
Service Discovery
Service Now
SOAP UI
Spark SQL
Testing
TOGAF
Research Method
Virtual Reality
Vue.js
Home
Recent Q&A
Feedback
Ask a Question
What is Python String
Home
>
Python
>
What is Python String
Dec 12, 2019
in
Python
Q: Python string
python-string
1
Answer
0
votes
Dec 12, 2019
In python, strings can be created by enclosing the character or the sequence of characters in the quotes. Python allows us to use single quotes, double quotes, or triple quotes to create the string.
Consider the following example in python to create a string.
str = "Hi Python !"
Here, if we check the type of the variable str using a python script
print(type(str)), then it will print string (str).
In python, strings are treated as the sequence of strings which means that python doesn't support the character data type instead a single character written as 'p' is treated as the string of length 1.
Strings indexing and splitting
Like other languages, the indexing of the python strings starts from 0. For example, The string "HELLO" is indexed as given in the below figure.
Python String
As shown in python, the slice operator [] is used to access the individual characters of the string. However, we can use the : (colon) operator in python to access the substring. Consider the following example.
Python String
Here, we must notice that the upper range given in the slice operator is always exclusive i.e., if str = 'python' is given, then str[1:3] will always include str[1] = 'p', str[2] = 'y', str[3] = 't' and nothing else.
Reassigning strings
Updating the content of the strings is as easy as assigning it to a new string. The string object doesn't support item assignment i.e., A string can only be replaced with a new string since its content can not be partially replaced. Strings are immutable in python.
Consider the following example.
Example 1
str = "HELLO"
str[0] = "h"
print(str)
Click here to read more about Python
Click here to read more about Insurance
Facebook
Twitter
LinkedIn
Related questions
0
votes
Q: What does the search method of re module do?
Jan 11
in
Python
#python-re-module
re-module
python-string
0
votes
Q: Can you please clarify what is a string in Python Language?
Aug 29, 2020
in
Python
#python-programming-language-string
0
votes
Q: What is Python String format and Python String replace?
May 17, 2020
in
Python
#python-string
#string-python
0
votes
Q: What Is A String In Python?
Dec 14, 2019
in
Python
#python-string
0
votes
Q: Is A String Immutable Or Mutable In Python?
Dec 14, 2019
in
Python
#python-string-mutable
+1
vote
Q: Does Python have a string 'contains' substring method?
Jan 10
in
Python
#python-string
string
python
substring
contains
...