Introduction
Setup
Operators
variable
String
Number
Dtype & Comment
Lists
Tuples
Sets
Dictionaries
if else statement
For Loop
While Loop
iterator & iterable
Pre-Built functions
Function
Decorators
generators
Types of errors
Exceptions Handling
OOP
Regular expression
Create module
OS module
Date module
Random module
Math
Statistics module
Exercise 1
Exercise 2
Exercise 3
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
A string is similar to text. Text is a string and you can also write a number as a string but when you write a number as a string then the number behaves Like a text. Then you can't perform any mathematical operation on it. You can also write code as a string but if you write code as string then code will become a text. To create a string, write that thing which you want to make or see as a string in the double or single quotation. If you write anything in a single or double quotation then it will work as a string.
Example:To convert anything into a string use the str() function.
Example:By using slicing, you can return a range of characters. For slicing, you have to specify the start index and the end index and between the start and end index use the colon symbol. After this, you will get a part of the string. A negative index means to start the slice from the end of the string.
An index is nothing but the position number of characters. Position or index number starts from zero. For
example, we have the word RafsanAhmad.Here R alphabet index number is 0 and the alphabet A index number is
6.
Remember one thing, starting number means, start according to the given index number from a word.
Suppose if we wrote 5 then the slicing will start from the number 5 character present in a word. It means the
output will have the character present in the number 5 position in the word. End index means slicing will stop
at the given index number.
Suppose we wrote the end index value is 9, then the slicing will stop at the 9th index number characters. So
we can say that we will get characters from starting index to the end index.
Here we will get letters from the 7th index to the 15th index. Here 7 means from 7 characters of RafsunAhmad slicing will start and 15 means this slicing will happen till the previous index of 15 characters.
Example:2In example 2 we will get all the characters from 0 indexes to 6 indexes. If we don't pass stating index value and just write end index value then the slicing will start from 0 indexes and will continue till end index.
Example:3Here we will get all the characters from the 5 index to the last index. If you don't pass the end index value and just pass starting index value then the slicing will start from starting index and slicing will happen till the last index.
Example:4Here you will get a -7 index to -15 index value. Here the slicing will start in the reverse direction(d to R)
In python to concatenate multiple strings, the + operator is used.
Example:1
A lot of work can be performed using escape characters like \n(for newline), etc.
Name | Code | Use |
---|---|---|
Tab | \t | Use to give space |
New Line | \n | Use to create newline |
Backslash | \\ | Use to insert a single quotation |
Single Quote | \' | Use to insert one \ (backslash). |
The upper function is used to convert letters into upper cases.
Example:The lower function is used to convert letters into lower case.
Example:capitalize function is used to convert the first letter of a sentence into upper case.
Example:endswith function returns true if the sentence ends with the given or specified value. If not then return false.
Example:find() function finds the given or specified value in the sentence and returns the index number. This method will find the first occurrence of that specified value. If the find function can't find anything then it will return -1.
Example:In the v variable of the find function, we wrote 1 and 20. It means that the find function will find that specified thing between 1 index to 20 indexes. We will see that between 1 to 20 index of the sentence there is no word fruit so the output is -1.
isalnum() function returns true if all characters in the string are alphanumeric. If not then return false.
Example:isalpha() function return true if all characters in the string are alphabet.If not then return false.
Example:This function prints the length of a string.
Example:isdecimal() function returns true if all characters in the string are decimals. If not then return false.
Example:isdigit() function returns true if all characters in the string are digit. If not then return false.
Example:isidentifier() function return true if all characters in the string is an identifier.If not then return false.
Example:islower() function returns true if all characters in the string are lower case. If not then return false.
Example:isnumeric() function return true if all characters in the string are numeric. If not then return false.
Example:istitle() function returns true if all characters in the string are titled. If not then return false.
Example:isupper() function return true if all characters in the string are upper case. If not then return false.
Example:join() function convert tuple,dictionary,list etc into one string.Here we separate the words using a separator.
Example:strip() function remove the space from the left and right side of a string. lstrip remove the space of the left side and rstrip remove the space of the right side.
Example:splitlines() function split string from line breaks and create a list.
Example:startswith() function return true if the string starts with that specified value and if not then returns false.
Example:swapcase() function swap uppercase word to lowercase and lower case word to upper case.
title() function converts each word's first letter into upper case.
Example:count() function returns the number of times the given value appears in the string.
Example:In the z variable of the count function, you write 1 and 20. It means that the count function will find how many times mango appears between 1 index to 20 indexes.
replace() function used to replace string value with another string value. In the function bracket first value is for that word or symbol that you want to replace and the second value is the word that you want to replace with.
Example:In the split function, a separator is used to separate. The default separator is space but you can use different separators according to your need like comma, colon, quotation, slash, etc. The split function separates numbers or strings by the given separator and returns all distinct values as a list.
Example: