2/3/2024 0 Comments Python string![]() Several lines and non-printable characters such as Para_str = """this is a long string that is made up of The syntax for triple quotes consists of three consecutive single or double quotes. Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters. M is the minimum total width and n is the number of digits to display after the decimal point (if appl.) '%%' leaves you with a single literal '%' Pad from left with zeros (instead of spaces) Leave a blank space before a positive numberĪdd the octal leading zero ( '0' ) or hexadecimal leading '0x' or '0X', depending on whether 'x' or 'X' were used. Other supported symbols and functionality are listed in the following table − Symbol String conversion via str() prior to formattingĮxponential notation (with lowercase 'e')Įxponential notation (with UPPERcase 'E') Here is the list of complete set of symbols which can be used along with % − Format Symbol Print "My name is %s and weight is %d kg!" % ('Zara', 21) This operator is unique to strings and makes up for the pack of having functions from C's printf() family. One of Python's coolest features is the string format operator %. Print r'\n' prints \n and print R'\n'prints \n The "r" can be lowercase (r) or uppercase (R) and must be placed immediately preceding the first quote mark. The syntax for raw strings is exactly the same as for normal strings with the exception of the raw string operator, the letter "r," which precedes the quotation marks. Raw String - Suppresses actual meaning of Escape characters. Membership - Returns true if a character does not exist in the given string Membership - Returns true if a character exists in the given string Range Slice - Gives the characters from the given range Slice - Gives the character from the given index Repetition - Creates new strings, concatenating multiple copies of the same Hexadecimal notation, where n is in the range 0.9, a.f, or A.FĪssume string variable a holds 'Hello' and variable b holds 'Python', then − OperatorĬoncatenation - Adds values on either side of the operator ![]() Octal notation, where n is in the range 0.7 When the above code is executed, it produces the following result −įollowing table is a list of escape or non-printable characters that can be represented with backslash notation.Īn escape character gets interpreted in a single quoted as well as double quoted strings. Print "Updated String :- ", var1 + 'Python'
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |