Category: 07. Python

  • Python Sets

    Set Sets are used to store multiple items in a single variable. Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage. A set is a collection which is unordered, unchangeable*, and unindexed. * Note: Set items are unchangeable, but you can remove items…

  • Python Tuples

    Tuple Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. A tuple is a collection which is ordered and unchangeable. Tuples are written with round brackets. ExampleGet…

  • Python Lists

    List Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage. Lists are created using square brackets: ExampleGet your own Python Server Create a List: List Items…

  • Python Operators

    Python Operators Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values: ExampleGet your own Python Server print(10 + 5) Run example » Python divides the operators in the following groups: Python Arithmetic Operators Arithmetic operators are used with numeric values to perform common mathematical…

  • Python Booleans

    Boolean Values In programming you often need to know if an expression is True or False. You can evaluate any expression in Python, and get one of two answers, True or False. When you compare two values, the expression is evaluated and Python returns the Boolean answer: ExampleGet your own Python Server When you run a condition in an if statement,…

  • Python Strings

    Strings Strings in python are surrounded by either single quotation marks, or double quotation marks. ‘hello’ is the same as “hello”. You can display a string literal with the print() function: ExampleGet your own Python Server Assign String to a Variable Assigning a string to a variable is done with the variable name followed by an equal sign and…

  • Python Casting

    Specify a Variable Type There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. Casting in python is therefore done using constructor functions: ExampleGet your…

  • Python Numbers

    Python Numbers There are three numeric types in Python: Variables of numeric types are created when you assign a value to them: ExampleGet your own Python Server To verify the type of any object in Python, use the type() function: Example Int Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.…

  • Python Data Types

    Built-in 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: Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool…

  • Python Variables

    Creating Variables Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. ExampleGet your own Python Server Variables do not need to be declared with any particular type, and can even change type after they have been set. Example Casting If you want to specify…