<jupyter_start><jupyter_text>Python basic built-in typesPython comes with a lot of [built-in types](https://docs.python.org/3/library/stdtypes.html). For the time being, we will focus on the most common _individual_ ones: * bool * int * float * string  Retrieving the type of an objectThe type of an object can be checked using the _type()_ function. To check if an object belongs to a specific type, use the _isinstance()_ function.<jupyter_code>x = list()
print("Type of x:", type(x))
print("Is x a list?", isinstance(x, list))
print("Is x a string?" , isinstance(x, str))<jupyter_output>Type of x: <class 'list'>
Is x a list? True
Is x a string? False<jupyter_text>Truth value testing: boolThe _bool_ type can have only two values: _True_ or _False_.<jupyter_code>print("Type of True?", type(True))
print("Type of False?", type(False))<jupyter_output>Type of True? <class 'bool'>
Type of False? <class 'bool'><jupyter_text>Numeric types: int/floatInteger numbers have unlimited precision (not limited to 32/64 bits as in other languages). Float numbers are usually represented as C _doubles_ internally, and you can check the machine's internal representation using _sys.float_info_.Float numbers also accept the values _nan_, _-inf_, and _+inf_ for Not a Number, negative infinity, and positive infinity.<jupyter_code>i = 123456789012345678901234567890
print("Type of i?", type(i))

f = 40.0
print("Type of f?", type(f))

pos_infinite = float("+inf")
print("Type of pos_infinite?", type(pos_infinite))
print("Value of pos_infinite?", pos_infinite)<jupyter_output>Type of i? <class 'int'>
Type of f? <class 'float'>
Type of pos_infinite? <class 'float'>
Value of pos_infinite? inf<jupyter_text>Python supports mixed arithmetic, and in this case the operand with the "narrower" type is widened to that of the other type. Numeric operationsThe usual operations are available: * sum: a+b* substraction: a-b* multiplication: a\*b* division: a/b* floored division: a//b* remainder: a%b* power: a\*\*b<jupyter_code>print("4+3:", 4+3)
print("4-3:", 4-3)
print("4*3:", 4*3)
print("4/3:", 4/3)
print("4//3:", 4//3)
# Floored division works with floats too
print("4.0//3.0:", 4.0//3.0)
print("4%3:", 4%3)
print("4**3:", 4**3)<jupyter_output>4+3: 7
4-3: 1
4*3: 12
4/3: 1.3333333333333333
4//3: 1
4.0//3.0: 1.0
4%3: 1
4**3: 64<jupyter_text>**Watch out!** Division works differently in Python2 and Python3. In Python2, if both operands are integers, the result will be integer. However in Python3 result be promoted to float.For further reference on numeric types, see the [numeric types](https://docs.python.org/3/library/stdtypes.htmlnumeric-types-int-float-complex) documentation. If you need to manipulate numbers, there are a lot of convenient functions in the [math](https://docs.python.org/3/library/math.html) module.  Text sequence: strTextual data in Python is handled with _str_ objects, or _strings_. These are immutable sequences of Unicode code points.There are several ways to write a string:<jupyter_code>print('This is a string')
print("This is a string as well")
print('''And this is also a string''')
print("""This too!""")<jupyter_output>This is a string
This is a string as well
And this is also a string
This too!<jupyter_text>Triple-quoted strings may span along multiple lines, and all associated whitespaces will be included in the string literal.<jupyter_code>s = """This is a multiline string
that spans over several lines

    see how whitespaces are preserved!
"""
print(s)<jupyter_output>This is a multiline string
that spans over several lines

    see how whitespaces are preserved!<jupyter_text>String literals that are part of a single expression containing only whitespaces between them will be implicitly coverted to a single string literal.<jupyter_code>s1 = "spam " "eggs"
s2 = "spam eggs"
print("Are s1 and s2 equal?", s1==s2)<jupyter_output>Are s1 and s2 equal? True<jupyter_text>**Watch out!** Strings are one of most dramatic changes between Python2 and Python3. In Python2, strings and byte strings are ASCII by default, and they can be forced to be Unicode using the 'u' prefix. In Python3 this is reversed: they are Unicode by default, and can be forced to be treated as bytes with the 'b' prefix. The [Unicode HOWTO](https://docs.python.org/3/howto/unicode.html) in Python's documentation contains more information on this topic. Strings are _sequences_, so they can be accessed by index. However, they are **immutable**, that is, they cannot be modified in place. Note that this immutability does not mean that strings cannot be worked with, as new strings can be created and assigned to new (or the same) variables.<jupyter_code>a = "immutable"
print("a:", a)
print("a[0]:", a[0])
try:
    a[0] = 'I'
except TypeError as type_error:
    print("TypeError:", type_error)

b = a.capitalize()
print("a:", a)
print("a[0]:", a[0])
print("b:", b)
print("b[0]:", b[0])<jupyter_output>a: immutable
a[0]: i
TypeError: 'str' object does not support item assignment
a: immutable
a[0]: i
b: Immutable
b[0]: I
{'fraction_non_alphanumeric': 0.11523941982912776, 'fraction_numerical': 0.02940592092191536, 'mean_word_length': 5.332075471698113, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '14799', 'license': 'MIT', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1583, 'n_words': 653, 'path': 'Notebooks/01_Basic_types.ipynb', 'repo_name': 'jvidalallende/python-knowledge-share', 'size': '5033'}