Python

Python Immutable Objects

For mutable objects, such as a list, to operate on a list, the contents within the list will change, for example. >>> l = [‘f’, ‘e’, ‘d’] >>> l.sort() >>> ; [‘d’, ‘e’, ‘f’] What about immutable objects, like string. >>> str = ‘hello’ >>> str.replace(‘h’, ‘F’) ‘Fello’ >>> str ‘hello’ Even though the string …

Python Immutable Objects Read More »

Python Dict And Set Example

1. Python Dict Introduction. Python has a built-in dictionary: dict. It is also called map in other coding languages, using key-value storage, it has an extremely fast lookup speed. For example, suppose you want to find the corresponding score according to the student’s name. If you use list, you need two lists. names = [‘Tom’, …

Python Dict And Set Example Read More »

Python List And Tuple Example

1. Python List One of Python’s built-in data types is list. A list is an ordered collection of elements that can be added and removed at any time. Below is an example of python list. The variable employees is a list. You can use the len() function to get the number of list elements >>> …

Python List And Tuple Example Read More »

Python Input / Output Example

This article will tell you how to use input / output in Python by examples. 1. Python Input. Open a terminal window and input python3 ( MacOS, Linux ), python( Windows ) to enter python interactive environment. If you want to input some character in code and save it to a variable, you can use …

Python Input / Output Example Read More »