📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 120definition

STRINGS AND STRING MANIPULATION · Part 5

Chapter 3: 4 · COMPUTER SCIENCE

refers A-F) %e or %E Exponential notation %f Floating point numbers %g or %G Short numbers in floating point or exponential notation. 12th Computer Chapter - - Escape sequence in python Escape sequences starts with a backslash and it can be interpreted differently. When you have use single quote to represent a string, all the single quotes inside the string must be escaped. Similar is the case with double quotes.

# String within triple quotes to display a string with single quote >>> print ('''They said, "What's there?"''') They said, "What's there?" # String within single quotes to display a string with single quote using escape sequence >>> print ('They said, "What\'s there?"') They said, "What's there?" # String within double quotes to display a string with single quote using escape sequence >>> print ("They said, \"What's there?\"") He said, "What's there?" Example Escape sequences supported by python Escape Sequence DESCRIPTION \newline Backslash and newline ignored \\ Backslash \' Single quote \" Double quote \a ASCII Bell \b ASCII Backspace \f ASCII Form feed \n ASCII Linefeed \r ASCII Carriage Return \t ASCII Horizontal Tab \v ASCII Vertical Tab \ooo Character with octal value ooo \xHH Character with hexadecimal value HH . The format( ) function The format( ) function used with strings is very versatile and powerful function used for formatting strings. The curly braces { } are used as placeholders or replacement fields which get replaced along with format( ) function. 12th Computer Chapter - - Strings and String Manipulation num1=int (input("Number : ")) num2=int (input("Number : ")) print ("The sum of { } and { } is { }".format(num1, num2,(num1+num2))) Out Put Number : Number : The sum of and is Example .

Built-in String functions Python supports the following built-in functions to manipulate string. Syntax Description Example len(str) Returns the length (no of characters) of the string. >>> A="Corporation" >>> print(len(A)) capitalize( ) Used to capitalize the first character of the string >>> city="chennai" >>> print(city.capitalize()) Chennai center(width, fillchar) Returns a string

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →