14.string in Python - Python String Functions
14.string in Python - Python String Functions
Home /
Tutorial /
String in Python
String in Python
By Manoj 7.6 K Views 22 min read Updated on March 25, 2022
In this module of the Python tutorial, we will learn in detail about the string data type in Python. We will further learn how to
create, access, and update strings. Toward the end of the tutorial, we will learn about various string operators and string
methods.
Python Tutorial
Comments in Python
Python Variables -
Constant, Global & Static
Variables
Numbers in Python
String in Python
Python Lists
Tuple in Python
Python Sets
Python Dictionary
Python Operators
Type conversion in
Python
Python If Else
Statements
Python Functions -
Define & Call a Functions
in Python
Lambda Function in
Python
Python Built in
Functions with Examples
Python Arrays
Python Modules
Python Dates
Python JSON
Python RegEx
PIP Python
Following is the list of all topics that are covered in this module.
String1 = ‘Intellipaat’
Print (Strings2)
After creating strings, they can be displayed on the screen using the print () method as shown in the above example. The
output of the above example will be as follows:
Intellipaat
Python Tutorial
Kick-start your career in Python with the perfect Python Course in New York now!
Example:
String1 = ‘intellipaat’
print (String1)
print (String1[0])
print (String1[1])
print (String1[-1])
Output:
Intellipaat
Example:
print (String1)
Output:
Original String:
Updated String:
Welcome to Intellipaat
Example:
print (String1)
del String1
print (String1)
Output:
Go for the most professional Python Course Online in Toronto for a stellar career now!
Operators Description
s1 = ‘ ’ Empty string
s1 + s2 Concatenate
s2 * 3 Repeat
s2[i] i=Index
s2[i:j] Slice
len(s2) Length
for x in s2 Iteration
‘m’ in s2 Membership
Operators Description
\v Vertical tab
\t Horizontal tab
\r Carriage return
\a ASCII bell
\f Form feed
\b Backspace
\e Escape (usually)
S1 = “hello”
S2 = “Intellipaat”
Become a Professional Python Programmer with this complete Python Training in Singapore!
Built-in Python String Methods and Python String Functions
Let’s understand some Python String Functions and standard built-in methods
string = “Intellipaat”
print(len(string))
print(len(string))
a = “Intellipaat”
print (a[2:5])
a = “Intellipaat”
print (a[:5])
a = “Intellipaat”
print (a[2:])
x = “intellipaat” [::-1]
print(x)
a=x.split()
print(a)
a = “Python tutorial”
b = “ by Intellipaat”
c = a + b
print(c)
print(“Python” == “Python”)
print(“Python” != “Python”)
True
True
False
False
b = “”
print(b.join(a))
a = ”I like Programming”
b = a.replace(“Programming”, “Python”)
print(b)
Go through the following table to understand some other Python String Methods:
center(width, fillchar) It returns a space-padded string with the original string centered to.
count(str, beg= 0,end=len(string)) It counts how many times ‘str’ occurs in a string or in the substring of a string
if the starting index ‘beg’ and the ending index ‘end’ are given.
encode(encoding=’UTF- It returns an encoded string version of a string; on error, the default is to raise
8′,errors=’strict’) a ValueError unless errors are given with ‘ignore’ or ‘replace’.
endswith(suffix, beg=0, It determines if a string or the substring of a string (if the starting index ‘beg’
end=len(string)) and the ending index ‘end’ are given) ends with a suffix; it returns true if so,
and false otherwise.
expandtabs(tabsize=8) It expands tabs in a string to multiple spaces; defaults to 8 spaces per tab if
the tab size is not provided.
find(str, beg=0 end=len(string)) It determines if ‘str’ occurs in a string or in the substring of a string if starting
index ‘beg’ and ending index ‘end’ are given and returns the index if found,
and −1 otherwise.
index(str, beg=0, end=len(string)) It works just like find() but raises an exception if ‘str’ not found.
isalnum() It returns true if a string has at least one character and all characters are
alphanumeric, and false otherwise.
isalpha() It returns true if a string has at least one character and all characters are
alphabetic, and false otherwise.
isdigit() It returns true if a string contains only digits, and false otherwise.
islower() It returns true if a string has at least one cased character and all other
characters are in lowercase, and false otherwise.
isupper() It returns true if a string has at least one cased character, and all other
characters are in uppercase, and false otherwise.
max(str) It returns the max alphabetical character from the string str.
min(str) It returns the min alphabetical character from the string str.
split(str=””, num=string.count(str)) It is used to split strings in Python according to the delimiter str (space if not
provided any) and returns the list of substrings in Python
splitlines( num=string.count(‘\n’)) It splits a string at the newlines and returns a list of each line with newlines
removed.
This brings us to the end of this module in Python Tutorial. Now, if you are interested in knowing why Python is the most
preferred language for data science, you can go through this Python Data Science tutorial.
Moreover, check out our Python Certification Course which will help me excel in my career and reach new heights. Also,
avail of the free guide to all the trending Python interview questions, created by the industry experts.
Previous Next
Course Schedule
Name Date
2022-05-07 2022-05-08
2022-05-14 2022-05-15
2022-05-21 2022-05-22
Python is very interesting,,, please I want you to teach me, python programs for FEBRUARY 19, 2021 AT 5:42 PM
games
Reply
samuel Adedeji
says:
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name * Email *
Post Comment
Browse Categories
Master Program
Big Data
Data Science
Business Intelligence
Salesforce
Cloud Computing
Mobile Development
Digital Marketing
Database
Programming
Testing
Project Management
Website Development
Chennai Jersey City Dubai Los Angeles San Francisco Singapore Toronto Bangalore Chicago Houston
Hyderabad London Melbourne New York San Jose Sydney Atlanta Austin Boston Charlotte Columbus
Dallas Denver Fremont Irving Mountain View Philadelphia Phoenix San Diego Seattle Sunnyvale
Washington Ashburn Kochi Kolkata Pune Noida Jaipur Delhi Gurgaon Mumbai Lucknow Gorakhpur
MEDIA
CONTACT US
TUTORIALS
COMMUNITY
INTERVIEW QUESTIONS