123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Detail Description About Python Strings

By Author: Infocampus
Total Articles: 277

Accessing Strings:
• In Python, Strings are stored as individual characters in a contiguous memory location.
• The benefit of using String is that it can be accessed from both the directions in forward and backward.
• Both forward as well as backward indexing are provided using Strings in Python.
o Forward indexing starts with 0,1,2,3,....
o Backward indexing starts with -1,-2,-3,-4,....
Strings Operators
There are basically 3 types of Operators supported by String:
1. Basic Operators.
2. Membership Operators.
3. Relational Operators.
Basic Operators:
There are two types of basic operators in String. They are "+" and "*".
String Concatenation Operator :(+)
The concatenation operator (+) concatenate two Strings and forms a new String.
Replication Operator: (*)
Replication operator uses two parameter for operation. One is the integer value and the other one is the String.
The Replication operator is used to repeat a string number of times. The string will be repeated the number of times which is given by the integer value.
Membership Operators
Membership Operators are already discussed in the Operators section. Let see with context of String.
There are two types of Membership operators:
1) in:"in" operator return true if a character or the entire substring is present in the specified string, otherwise false.
2) not in:"not in" operator return true if a character or entire substring does not exist in the specified string, otherwise false.
Relational Operators:
All the comparison operators i.e., (=,==,!=,) are also applicable to strings. The Strings are compared based on the ASCII value or Unicode(i.e., dictionary Order).
Slice Notation:
String slice can be defined as substring which is the part of string. Therefore further substring can be obtained from a string.
There can be many forms to slice a string. As string can be accessed or indexed from both the direction and hence string can also be sliced from both the direction that is left and right.
String Functions and Methods:
There are many predefined or built in functions in String. They are as follows:
capitalize() It capitalizes the first character of the String.
count(string,begin,end) Counts number of times substring occurs in a String between begin and end index.
endswith(suffix ,begin=0,end=n) Returns a Boolean value if the string terminates with given suffix between begin and end.
find(substring ,beginIndex, endIndex) It returns the index value of the string where substring is found between begin index and end index.
index(subsring, beginIndex, endIndex) Same as find() except it raises an exception if string is not found.
isalnum() It returns True if characters in the string are alphanumeric i.e., alphabets or numbers and there is at least 1 character. Otherwise it returns False.
isalpha() It returns True when all the characters are alphabets and there is at least one character, otherwise False.
isdigit() It returns True if all the characters are digit and there is at least one character, otherwise False.
islower() It returns True if the characters of a string are in lower case, otherwise False.
isupper() It returns False if characters of a string are in Upper case, otherwise False.
isspace() It returns True if the characters of a string are whitespace, otherwise false.
len(string) len() returns the length of a string.
lower() Converts all the characters of a string to Lower case.
upper() Converts all the characters of a string to Upper Case.
startswith(str ,begin=0,end=n) Returns a Boolean value if the string starts with given str between begin and end.
swapcase() Inverts case of all characters in a string.
lstrip() Remove all leading whitespace of a string. It can also be used to remove particular character from leading.
rstrip() Remove all trailing whitespace of a string. It can also be used to remove particular character from trailing.
Python List
1).Python lists are the data structure that is capable of holding different type of data.
2).Python lists are mutable i.e., Python will not create a new list if we modify an element in the list.
3).It is a container that holds other objects in a given order. Different operation like insertion and deletion can be performed on lists.
4).A list can be composed by storing a sequence of different type of values separated by commas.
5).A python list is enclosed between square([]) brackets.
6).The elements are stored in the index basis with starting index as 0.
List Operations:
Various Operations can be performed on List. Operations performed on List are given as:
a) Adding Lists:
Lists can be added by using the concatenation operator(+) to join two lists.
Functions and Methods of Lists:
There are many Built-in functions and methods for Lists. They are as follows:
There are following List functions:
Function Description
min(list) Returns the minimum value from the list given.
max(list) Returns the largest value from the given list.
len(list) Returns number of elements in a list.
cmp(list1,list2) Compares the two list.
list(sequence) Takes sequence types and converts them to lists.

Total Views: 40Word Count: 715See All articles From Author

Computer Programming Articles

1. Java Vs Python: Which Programming Language To Master?
Author: Individual

2. 9 Myths Regarding Seo That You Simply Ought To Stop Basic Cognitive Process Nowadays
Author: emly

3. Selenium Testing – Common And Difficult Interview Questions
Author: Siyaram Ray

4. Concrete Scanning
Author: concrete scanning

5. Future Of Java Technology
Author: Individual

6. El Mejor Método Absoluto Para Lograr La Conversión De Ost A Pst
Author: EdbMails

7. Native Vs. Hybrid App Development: Which Approach To Choose In 2018?
Author: Alex Porubay

8. What To Do When Norton’s Firewall Block A Genuine Website?
Author: Daisy Matilda

9. Need Of Fundamental Web Development Knowledge
Author: Siyaram Ray

10. Data Analytics And Data Visualization - Job Opportunities
Author: pankaj singh

11. Creating Website – Essential Requirement For Web Development
Author: Siyaram Ray

12. Choosing The Right Technology For Your Mobile App
Author: Jules Arkley

13. Readymade Alibaba Clone Script For Next Generation
Author: Riya Dubay

14. Web Development – Top Programming Languages Needs To Learn
Author: Siyaram Ray

15. Why Redundancy, Scalability And High Availability Are Essential For Your Contact Center?
Author: Teckinfo

Login To Account
Login Email:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: