<jupyter_start><jupyter_text>Data Types In programming, data type is an important concept.Variables can store data of different types, and different types can do different things.Python has the following data types built-in by default, in these categories:1. Text Type:	str2. Numeric Types:	int, float, complex3. Sequence Types:	list, tuple, range4. Mapping Type:	dict5. Set Types:	set, frozenset6. Boolean Type:	bool7. Binary Types:	bytes, bytearray, memoryview  Text Type  str<jupyter_code>a = "Himanshu"
print(a)
print(type(a))
# multiline string
a = '''
    Hi
    How are you?
'''
print(a)
# Accessing particular element from the string
a = "Hi, How are you"
print(a[6]) #indexing starting from zero
# Slicing of string
# Syntax:- a[start:end:jump]
a = a[4:7:2] #Here 7th position is not included
print(a)
help(str)
s = "Hello, How are you"<jupyter_output><empty_output><jupyter_text>Capitalize<jupyter_code>s.capitalize() #More specifically, make the first character have upper case and the rest lowercase.<jupyter_output><empty_output><jupyter_text>Casefold<jupyter_code>s.casefold() #Return a lowercase string<jupyter_output><empty_output><jupyter_text>Center<jupyter_code>print(s.center(22))
'''
center(self, width, fillchar=' ', /)
 |      Return a centered string of length width.
 |      
 |      Padding is done using the specified fill character (default is a space).
'''
print(s.center(24,'@'))<jupyter_output>Hello, How are you  
@@@Hello, How are you@@@<jupyter_text>Count<jupyter_code>s.count('e')<jupyter_output><empty_output><jupyter_text>Encode<jupyter_code>s.encode()
txt = "My# name is Ståle"

print(txt.encode(encoding="ascii",errors="backslashreplace"))
print(txt.encode(encoding="ascii",errors="ignore"))
print(txt.encode(encoding="ascii",errors="namereplace"))
print(txt.encode(encoding="ascii",errors="replace"))
print(txt.encode(encoding="ascii",errors="xmlcharrefreplace"))<jupyter_output><empty_output><jupyter_text>Endswith<jupyter_code>print(s.endswith("!!!"))
print(s.endswith("you"))<jupyter_output>False
True<jupyter_text>Expandtabs<jupyter_code>a = "Himanshu\tgoyal\tss"
a.expandtabs(20) #intially the value is equal to tab size i.e 8<jupyter_output><empty_output><jupyter_text>Find<jupyter_code>s.find("ar")
s.find("h")<jupyter_output><empty_output><jupyter_text>Format<jupyter_code>String1 = "{} {} {}".format('Geeks', 'For', 'Life') 
print("Print String in default order: ") 
print(String1) 
  
# Positional Formatting 
String1 = "{1} {0} {2}".format('Geeks', 'For', 'Life') 
print("\nPrint String in Positional order: ") 
print(String1) 
  
# Keyword Formatting 
String1 = "{l} {f} {g}".format(g = 'Geeks', f = 'For', l = 'Life') 
print("\nPrint String in order of Keywords: ") 
print(String1)
String1 = "{0:b}".format(16) 
print("\nBinary representation of 16 is ") 
print(String1) 
  
# Formatting of Floats 
String1 = "{0:e}".format(165.6458) 
print("\nExponent representation of 165.6458 is ") 
print(String1) 
  
# Rounding off Integers 
String1 = "{0:.2f}".format(1/6) 
print("\none-sixth is : ") 
print(String1) 
# String alignment 
String1 = "|{:<10}|{:^10}|{:>10}|".format('Geeks','for','Geeks') 
print("\nLeft, center and right alignment with Formatting: ") 
print(String1) 
  
# To demonstrate aligning of spaces  
String1 = "\n{0:^16} was founded in {1:<4}!".format("GeeksforGeeks", 2009) 
print(String1) 
Integer1 = 12.3456789
print("Formatting in 3.2f format: ") 
print('The value of Integer1 is %3.2f' %Integer1) 
print("\nFormatting in 3.4f format: ") 
print('The value of Integer1 is %3.4f' %Integer1)<jupyter_output>Formatting in 3.2f format: 
The value of Integer1 is 12.35

Formatting in 3.4f format: 
The value of Integer1 is 12.3457<jupyter_text>Format_Map<jupyter_code>point = {'x':4,'y':-5}
print('{x} {y}'.format_map(point))

point = {'x':4,'y':-5, 'z': 0}
print('{x} {y} {z}'.format_map(point))
class Coordinate(dict):
    def __missing__(self, key):
      return key


print('({x}, {y})'.format_map(Coordinate(x='6')))
print('({x}, {y})'.format_map(Coordinate(y='5')))
print('({x}, {y})'.format_map(Coordinate(x='6', y='5')))<jupyter_output>(6, y)
(x, 5)
(6, 5)<jupyter_text>Index<jupyter_code>print(s.index('o'))
print(s.index('How'))<jupyter_output>4
7<jupyter_text>isalnum<jupyter_code>#isalnum checks string contains only alphabet and numbers only.
string = "Abcd123"
print(string.isalnum())
string = "Abcd@123"
print(string.isalnum())
string = "!@#$"
print(string.isalnum())<jupyter_output>True
False
False<jupyter_text>isalpha<jupyter_code>string = "Himanshu"
print(string.isalpha())
string = "Himanshu123"
print(string.isalpha())
string = "Hima!@"
print(string.isalpha())<jupyter_output>True
False
False<jupyter_text>isascii<jupyter_code>a = "å"
print(a.isascii())
a = " "
print(a.isascii())
a = "a"
print(a.isascii())<jupyter_output>False
True
True<jupyter_text>isdecimal<jupyter_code>a = "123454"
print(a.isdecimal())
a = "Hi12"
print(a.isdecimal())
a = "123"
print(a.isdigit())
a = "12anc"
print(a.isdigit())
help(str)<jupyter_output>Help on class str in module builtins:

class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |  
 |  Create a new string object from the given object. If encoding or
 |  errors is specified, then the object must expose a data buffer
 |  that will be decoded using the given encoding and error handler.
 |  Otherwise, returns the result of object.__str__() (if defined)
 |  or repr(object).
 |  encoding defaults to sys.getdefaultencoding().
 |  errors defaults to 'strict'.
 |  
 |  Methods defined here:
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __format__(self, format_spec, /)
 |      Return a formatted version of the string as described by format_spec.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  [...]<jupyter_text>isidentifier<jupyter_code>a = 'abc'
b = 'abc123'
c = '123abc'
d = '23'
print(a.isidentifier())
print(b.isidentifier())
print(c.isidentifier())
print(d.isidentifier())<jupyter_output>True
True
False
False<jupyter_text>islower<jupyter_code>a = "abc"
b = "Abc"
c = "ABC"
d = "abc123"
print(a.islower())
print(b.islower())
print(c.islower())
print(d.islower())<jupyter_output>True
False
False
True<jupyter_text>isnumeric<jupyter_code>a = "123"
b = "abc123"
print(a.isnumeric())
print(b.isnumeric())<jupyter_output>True
False<jupyter_text>isprintable<jupyter_code>txt = "Hello! Are you #1?"

x = txt.isprintable()

print(x)
txt = "Hello! \n Are you #1?"

x = txt.isprintable()

print(x)<jupyter_output>True
False<jupyter_text>isspace<jupyter_code>a = ""
b = " "
c = "            "
d = "fsdff sdfsd    sdfd"
e = "                e"
print(a.isspace())
print(b.isspace())
print(c.isspace())
print(d.isspace())
print(e.isspace())<jupyter_output>False
True
True
False
False<jupyter_text>istitle<jupyter_code>a = "<NAME>"
b = "<NAME>"
print(a.istitle())
print(b.istitle())<jupyter_output>True
False<jupyter_text>isupper<jupyter_code>a = "Himanshu"
b = "HiMaNsHu"
c = "HIMANSHU"
print(a.isupper())
print(b.isupper())
print(c.isupper())<jupyter_output>False
False
True<jupyter_text>join<jupyter_code>myTuple = ("John", "Peter", "Vicky")

x = "#".join(myTuple)

print(x)

myTuple = ("John", "Peter", "Vicky")

x = " ".join(myTuple)

print(x)

myDict = {"name": "John", "country": "Norway"}
mySeparator = "TEST"

x = mySeparator.join(myDict)

print(x)<jupyter_output>John#Peter#Vicky
<NAME>
nameTESTcountry<jupyter_text>ljust The resultant left aligned string expanding the given width.<jupyter_code>lstr = "I love geeksforgeeks"
  
# Printing the original string 
print ("The original string is : \n", lstr, "\n") 
  
# Printing the left aligned  
# string with "-" padding  
print ("The left aligned string is : ") 
print (lstr.ljust(40, '-'))<jupyter_output>The original string is : 
 I love geeksforgeeks 

The left aligned string is : 
I love geeksforgeeks--------------------<jupyter_text>lower<jupyter_code>a = "HiMaNsHu"
a.lower()<jupyter_output><empty_output><jupyter_text>lstrip<jupyter_code>string = """    geeks for geeks    """ 
  
# prints the string without stripping 
print(string)  
  
# prints the string by removing leading and trailing whitespaces 
print(string.strip())    
  
# prints the string by removing geeks 
print(string.strip(' geeks'))<jupyter_output>geeks for geeks    
geeks for geeks
for<jupyter_text>partition<jupyter_code>string = "pawan is a good"
  
# 'is' separator is found 
print(string.partition('is ')) 
  
# 'not' separator is not found 
print(string.partition('bad ')) 
  
string = "pawan is a good, isn't it"
  
# splits at first occurrence of 'is' 
print(string.partition('is'))<jupyter_output>('pawan ', 'is ', 'a good')
('pawan is a good', '', '')
('pawan ', 'is', " a good, isn't it")<jupyter_text>replace<jupyter_code>input   = 'helloABworld'
pattern = 'AB'
replaceWith = 'C'
print(input.replace(pattern,replaceWith))<jupyter_output>helloCworld<jupyter_text>rfind rfind() method returns the highest index of the substring if found in given string. If not found then it returns -1.<jupyter_code>word = 'geeks for geeks'
  
# Returns highest index of the substring 
result = word.rfind('geeks') 
print ("Substring 'geeks' found at index :", result ) 
  
result = word.rfind('for') 
print ("Substring 'for' found at index :", result ) 
  
word = 'CatBatSatMatGate'
  
# Returns highest index of the substring 
result = word.rfind('ate') 
print("Substring 'ate' found at index :", result)<jupyter_output>Substring 'geeks' found at index : 10
Substring 'for' found at index : 6
Substring 'ate' found at index : 13<jupyter_text>rindex<jupyter_code>txt = "Mi casa, su casa hi, casa."

x = txt.rindex("casa")

print(x)
#difference between rfind and rindex
txt = "Hello, welcome to my world."

print(txt.rfind("q"))
print(txt.rindex("q"))<jupyter_output>-1<jupyter_text>rjust<jupyter_code>#Syntax
#str.rjust(width[, fillchar])
str = "this is string example....wow!!!";
print(str.rjust(50, '0'))<jupyter_output>000000000000000000this is string example....wow!!!<jupyter_text>rpartition<jupyter_code>txt = "I could eat bananas all day, bananas are my favorite fruit"

x = txt.rpartition("bananas")

print(x)<jupyter_output>('I could eat bananas all day, ', 'bananas', ' are my favorite fruit')<jupyter_text>rsplit<jupyter_code># The rsplit() method splits a string into a list, starting from the right.
txt = "apple, banana, cherry"

x = txt.rsplit(", ")

print(x)<jupyter_output>['apple', 'banana', 'cherry']<jupyter_text>rstrip<jupyter_code># The rstrip() method removes any trailing characters (characters at the end a string), space is the default trailing character to remove.

txt = "     banana     "

x = txt.rstrip()

print("of all fruits", x, "is my favorite")<jupyter_output>of all fruits      banana is my favorite<jupyter_text>split<jupyter_code># The split() method splits a string into a list.

txt = "welcome to the jungle"

x = txt.split() # Default is space

print(x)<jupyter_output>['welcome', 'to', 'the', 'jungle']<jupyter_text>splitlines<jupyter_code># The splitlines() method splits a string into a list. The splitting is done at line breaks.

txt = "Thank you for the music\nWelcome to the jungle"

x = txt.splitlines()

print(x)<jupyter_output>['Thank you for the music', 'Welcome to the jungle']<jupyter_text>startswith<jupyter_code># The startswith() method returns True if the string starts with the specified value, otherwise False.

txt = "Hello, welcome to my world."

x = txt.startswith("Hello")

print(x)<jupyter_output>True<jupyter_text>strip<jupyter_code># The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove)

txt = "     banana     "

x = txt.strip()

print("of all fruits", x, "is my favorite")<jupyter_output>of all fruits banana is my favorite<jupyter_text>swapcase<jupyter_code># The string swapcase() method converts all uppercase characters to lowercase and vice versa of the given string, and returns it.

string = "gEEksFORgeeks"
  
# prints after swappong all cases 
print(string.swapcase())    
  
string = "striver" 
print(string.swapcase())<jupyter_output>GeeKSforGEEKS
STRIVER<jupyter_text>title<jupyter_code># The title() method returns a string where the first character in every word is upper case. Like a header, or a title.

txt = "Welcome to my world"

x = txt.title()

print(x)<jupyter_output>Welcome To My World<jupyter_text>translate<jupyter_code># The translate() method returns a string where some specified characters are replaced with the character described in a dictionary, or in a mapping table.

#use a dictionary with ascii codes to replace 83 (S) with 80 (P):
mydict = {83:  80};
txt = "Hello Sam!";
print(txt.translate(mydict));<jupyter_output>Hello Pam!<jupyter_text>upper<jupyter_code>txt = "Hello my friends"

x = txt.upper()

print(x)<jupyter_output>HELLO MY FRIENDS<jupyter_text>zfill<jupyter_code># The zfill() method adds zeros (0) at the beginning of the string, until it reaches the specified length.

txt = "50"

x = txt.zfill(10)

print(x)<jupyter_output>0000000050<jupyter_text>Escape Sequences<jupyter_code>String1 = '''I'm a "Geek"'''
print("Initial String with use of Triple Quotes: ") 
print(String1) 
  
# Escaping Single Quote  
String1 = 'I\'m a "Geek"'
print("\nEscaping Single Quote: ") 
print(String1) 
  
# Escaping Doule Quotes 
String1 = "I'm a \"Geek\""
print("\nEscaping Double Quotes: ") 
print(String1) 
  
# Printing Paths with the  
# use of Escape Sequences 
String1 = "C:\\Python\\Geeks\\"
print("\nEscaping Backslashes: ") 
print(String1) 
# Printing Geeks in HEX 
String1 = "This is \x47\x65\x65\x6b\x73 in \x48\x45\x58"
print("\nPrinting in HEX with the use of Escape Sequences: ") 
print(String1) 
  
# Using raw String to  
# ignore Escape Sequences 
String1 = r"This is \x47\x65\x65\x6b\x73 in \x48\x45\x58"
print("\nPrinting Raw String in HEX Format: ") 
print(String1)<jupyter_output>Printing in HEX with the use of Escape Sequences: 
This is Geeks in HEX

Printing Raw String in HEX Format: 
This is \x47\x65\x65\x6b\x73 in \x48\x45\x58<jupyter_text>Explanation:-'\x61'will evaluate to 'a', because 61 is the hexadecimal value of 97, which represents a in ASCII<jupyter_code>print("line1 \
line2 \
line3") #Backslash and newline ignored
print("\\") #Backslash (\)
print('\'') #Single quote (')
print("\"") #Doublr quote(")
print("\a") #ASCII Bell (BEL)
print("Hello \b World!") #ASCII Backspace (BS)
print("Hello \f World!") #ASCII Formfeed (FF)
print("Hello \n World!") #ASCII Linefeed (LF)
print("Hello \r World!") #ASCII Carriage Return (CR)
print("Hello \t World!") #ASCII Horizontal Tab (TAB)
print("Hello \v World!") #ASCII Vertical Tab (VT)
print("\110\145\154\154\157\40\127\157\162\154\144\41") #Character with octal value ooo
print("\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21") #Character with hex value hh

print("\N{SOLIDUS} \N{BLACK SPADE SUIT}")
print("\u1011")
print("\u4567")<jupyter_output>䕧
{'fraction_non_alphanumeric': 0.14833102903416948, 'fraction_numerical': 0.023108828757653566, 'mean_word_length': 5.3423799582463465, 'pattern_counts': {'":': 2, '<': 152, '<?xml version=': 0, '>': 154, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '46', 'dir': 'jupyter-structured-clean-dedup', 'id': '551523', 'license': 'Apache-2.0', 'n_tokens_mistral': 5923, 'n_tokens_neox': 5651, 'n_words': 1419, 'path': 'Data type-String and Escape Sequences.ipynb', 'repo_name': 'himanshu-1205/Python-Tutorial', 'size': '15215'}