Python Strings

Anurag Verma
2 min readJul 12, 2021

What are Python Strings?
Python strings are sequences of characters. It is an ordered collection and immutable.’ str’ class is utilized for python strings. Identify the class of variables using the type() technique.
e.g.
type(“ Felines are charming”).

Declare Python String.

We can utilize single quotes -LRB-’’-RRB- or double quotes for stating python strings.
e.g.
s=’ Felines are adorable’.

Usage Quotes inside Python String.

We can not use the exact same quote mark for use of quotes inside the python string.
s=” Cats are “cute””.
For a double quote, we can utilize single quotes or for a single quote, we can utilize double quotes.

In python, formatting approaches are available as follows:.

f-strings.

f-string python format strategy usage for formatting the string using the letter ‘f’ precedes the string, and the variables are used utilizing curly braces” “ in their locations.

format() approach.

format() method use to format python string.It use argument separated by commas.
Syntax:.
String.format( value1, value2,).

% operator.

% operator used for to access variable.% s is used for string.

Escape Sequences in Python.

In Python following series are offered.

\’ Single Quote.
\ \ Backslash.
\ n New Line.
\ r Carriage Return.
\ t Tab.
\ b Backspace.
\ f Type Feed.
\ ooo Octal value.
\ xhh Hex worth.

Python String Functions.

Python offers us with numerous functions that we can apply on strings or to develop strings.

len().
It returns the length of the string.

str().
str in python used for type casting into string.str in python transforms int to string, float to string, complex to string and so on.

lower() and upper().
Get uppercase and lowercase strings using lower() approach and upper() method respectively.

strip().
Strip() technique eliminates whitespaces from the beginning and end of the string.

Summary.

In this blog site, we learned about python strings with string functions and Operators, and how to declare and access them.
We likewise found out about python string concatenation and formatters in python.
Finally, we learned about Python string functions that we can perform on strings.

--

--