0% found this document useful (0 votes)
4 views

string (1)

Strings are a fundamental data type in Python, representing a sequence of characters and commonly used for input and output operations. They can be accessed using indexing, both positive and negative, to retrieve specific characters. Various string methods are available to manipulate and format strings, including capitalization, case conversion, and substring counting.

Uploaded by

purabupadhyay06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

string (1)

Strings are a fundamental data type in Python, representing a sequence of characters and commonly used for input and output operations. They can be accessed using indexing, both positive and negative, to retrieve specific characters. Various string methods are available to manipulate and format strings, including capitalization, case conversion, and substring counting.

Uploaded by

purabupadhyay06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

> string : string are fundamental in computer science and processing string in a common task in

programming we have string used in input and output the input function return a string form
keyboard and print function display a string on the console.string are considered as the most
popular data type present in python language string is a sequence of one or more character
here the character can be letter,digit,white space,or any other syntax an string can created by
enclosing one or more character in single,double and triple.

>accessing character in a string by index number


1.indexing : each individual character in a string can be accessed using a technique called
indexing.the index character to be accessed in the string and is written in square brackets[] the
index of first character (from left) in the string is 0 and last character is n-1 where n is the length
of the string if we give index value out this range then we get an index error.

2.negative indexing : we can also print the element by using negative indexes. The negative
index start from last element and denoted -1 . negative index is very helpful in python string
when we have to print element from last and we dont know the length of the string. Negative
index are used when we want to access the character of the string from right to left

👍
>string method
1.capitalize : it converts the initial letter of the string to uppercase
2.casefold() : it converts the entire string to lowercase.
3.center() : it aligns the string at the center of the specified length.
4.count(): it returns the number of times a substring occurs in the given string.
5.encode() : it converts the string into the encoded version.
6.starwith() : it returns true if the given string starts with a specified substring.otherwise false.
7.endwith() : it returns true if the given string ends with a specified substring.otherwise false.
8.expandtabs() : the method sets the tab size to the specified number of whitespace.the default
tab size is 8 character space.
9.format() : it helps to format the string by making use of placeholders.

You might also like