Author: admin

  • Python JSON

    JSON in Python Python has a built-in package called json, which can be used to work with JSON data. ExampleGet your own Python Server Import the json module: Parse JSON – Convert from JSON to Python If you have a JSON string, you can parse it by using the json.loads() method. The result will be a Python dictionary. Example…

  • Python Datetime

    Python Dates A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects. ExampleGet your own Python Server Import the datetime module and display the current date: Date Output When we execute the code from the example above the result will…

  • Python Modules

    What is a Module? Consider a module to be the same as a code library. A file containing a set of functions you want to include in your application. Create a Module To create a module just save the code you want in a file with the file extension .py: ExampleGet your own Python Server Save…

  • Python Scope

    Local Scope A variable created inside a function belongs to the local scope of that function, and can only be used inside that function. ExampleGet your own Python Server A variable created inside a function is available inside that function: Function Inside Function As explained in the example above, the variable x is not available outside the function, but…

  • Python Polymorphism

    Function Polymorphism An example of a Python function that can be used on different objects is the len() function. String For strings len() returns the number of characters: ExampleGet your own Python Server Tuple For tuples len() returns the number of items in the tuple: Example Dictionary For dictionaries len() returns the number of key/value pairs in the dictionary: Example Class Polymorphism Polymorphism…

  • Python Dictionaries

    Dictionary Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered*, changeable and do not allow duplicates. As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered. Dictionaries are written with curly brackets, and have keys and values: ExampleGet your own Python Server…

  • 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…