Python Tutorials

Welcome to PyTut. Below you can find short tutorials of commonly used Python data types, constants, and functions.

Python Data Types

Python bool Data Type (True or False Boolean Value)

This page explains the bool (boolean - True/False) data type in Python, its basic characteristics, typical use cases, and common operations. Basic characteristics The name bool is short for boolean, meaning true/false. There are only two possible values of the bool type: True or False. True and False are [more...]

Python int (Integer) Data Type

This page is a summary of Python int (integer) data type - its basic characteristics, how to create an int, how to convert other data types to int, basic arithmetic and comparison operations, and typical use cases. Basic characteristics Python int data type represents integers = whole numbers = numbers without decimal point. [more...]

Python float (Floating Point Number) Data Type

This page is a summary of Python float (floating-point number or decimal number) data type - its basic characteristics, how to create a float variable, how to convert other data types to float, and basic arithmetic and comparison operations. It also explains the problem of floating point imprecision and typical situations [more...]

Python str (String) Data Type

Python str (string) is a sequence of characters. You can find a character within a string by indexing. Position starts with zero. Negative numbers start from the end of string. You can find string length (number of characters) using the len() function. Strings can be typed with single or double [more...]

Python list Data Type

Python list is a mutable ordered collection of items: The items can be of different types: There can be duplicates (this is main difference from set): Main difference between list and tuple is that list is mutable = can be modified later: [more...]

Python tuple Data Type

Python tuple is an immutable ordered collection of items: Most characteristic are the same for tuples and lists. Both can contain zero, one, or more items, which can be duplicate and can be of different types. You can find any item from a tuple using its index (start from zero). [more...]

Python set Data Type

Python set is a collection of items: Its main difference from list and tuple is that all items must be unique - there can't be duplicates. Finding a set item by its index does not work, unlike tuples and lists. [more...]

Python dict (Dictionary) Data Type

Python dict (dictionary) is a collection of key-value pairs. You can find a value by its key: You can also change a value by its key: You can add a new key-value pair in the same way: Keys must be unique, values can be duplicate. Values can be of different [more...]

All data types

Python Constants

Python None Constant

Python None constant is used to represent a null value, a missing value, or no value. Setting a variable to None To set a variable None, just use the None keyword. None starts with uppercase N None starts with capital N. Lowercase n does not work. None (with uppercase N) [more...]

Python Ellipsis (Three Dots) Constant

This page explains the Ellipsis (three dots) constant in Python, its use cases, and relationships to other built-in constants like True, False, or None. Ellipsis = three dots The Ellipsis constant is returned when typing a literal ellipsis ... (three dots) or by typing the keyword Ellipsis: Both are identical and interchangeable: [more...]

Python NotImplemented Constant

This page explains Python NotImplemented constant, its typical use cases, and its difference from NotImplementedError. Typical use cases The built-in NotImplemented constant is used to indicate that an operation or method is not implemented for a given object. It is typically used with comparison methods such as __eq__(), __lt__(), __gt__(), [more...]

Python Functions

Python abs() Function

The abs() built-in Python function calculates absolute value of a number. It takes one input x. For negative numbers (x < 0) it returns -x. For positive numbers and zero (x >= 0) it returns x. Input data types Typical arguments to the abs() function are int or float types. The argument [more...]

Python all() Function

The built-in Python function all() checks if all items in a sequence (such as a list, tuple, or set) are True. It takes one input iterable. If all items in iterable evaluate to True, all(iterable) returns True. Otherwise, if at least one item evaluates to False, it returns False. [more...]

Python any() Function

Python any() function takes a sequence as input (such as a tuple or list) and checks if at least one item is True. If at least one item in the input iterable is True, any() returns True. If all items evaluate to False, it returns False. If the input iterable [more...]

Python type() Function

Python type() function has two variants. The more common variant with a single argument is used to determine the data type of a variable or object in Python. It returns the class of the object that is passed as an argument. This page explains this variant and its use cases. [more...]

Python type() Function with Three Arguments

The type() function is commonly used with a single argument - the variable whose data type we want to check. It returns an existing type object - the type of the input variable. For instance, if passed an int like 123, it returns the int type. However, there is another variant with [more...]

By remaining on this website or using its content, you confirm that you have read and agree with the Terms of Use Agreement.

We are not liable for any damages resulting from using this website. Any information may be inaccurate or incomplete. See full Limitation of Liability.

Content may include affiliate links, which means we may earn commission if you buy on the linked website. See full Affiliate and Referral Disclosure.

We use cookies and similar technology to improve user experience and analyze traffic. See full Cookie Policy.

See also Privacy Policy on how we collect and handle user data.

© 2023 PyTut