Beginner Python Programming: The Insider Guide to Basic Python Programming Fundamentals by Richard Ozer & Python Programming

Beginner Python Programming: The Insider Guide to Basic Python Programming Fundamentals by Richard Ozer & Python Programming

Author:Richard Ozer & Python Programming
Language: eng
Format: azw3
Published: 2017-08-28T07:00:00+00:00


All you have done here is create three different variables (‘a’, ‘s’, and ‘l’) that point to specific objects (‘2’, ‘adt’, and [‘a string’, 456, (‘a’, ‘tuple’, ‘inside’, ‘a’, ‘list’)]), and all of this has been placed into Python’s memory so it can conveniently access it when necessary. So, should you ever want to, you can do, and change these variables. For example:

● a = 2

s = ‘yut’

l = [‘a simple list’, 80, 17]

The variables stayed the same, but the objects assigned to the variables changed and Python didn’t kick you out of it. This is because the objects are mutable, but the immutable objects are the ‘a’, the ‘s’, and the ‘l’. This might seem like common sense, but once you start using more complex and complicated variables that are assigned more complicated objects, that distinction will help you root yourself in what you are doing and make sure you are doing it correctly. In many situations, understanding this difference in behavior isn’t necessary, but being familiar with the concept will help explain why we manipulate all the stuff to the right of the equal sign but not the things to the left of it once they are assigned.

With regard to data types, this is another reason user functions come into play. Remember when we discussed ‘str()’ and ‘int()’ user functions? These functions are to help Python reconcile between different data types you are using within the lines of code you are writing. What those functions do is it makes two different types of data that shouldn’t be compatible and carves them out so they are. Think of the user functions as knives and what you place within them are pieces of wood. The user functions whittle the two data types down into interlocking, compatible pieces of wood that then fit together correctly in order to keep the chain of command going.

That is one way to manipulate data types within Python, and you’ve already learned about it!

Two of the most prominent data types in Python are lists and dictionaries. Tuples are important as well, but we will break those down in a later chapter. For now, let’s focus on dictionaries, lists, and what their purpose is within Python.

A list is simply a sequence of items in a specific order. It is the most used data type in Python, and it is incredibly flexible in its properties, meaning it is mutable. The great thing about a list is that all of the items within it don’t have to be the same type of item, so you can mix integers with predetermined variables along with random strings of characters for Python to spit out at the end once the list and the code it is embedded into is executed.

Creating a list and defining it as such is easy, because all it takes are commas to separate the items while they are enclosed in brackets ([]). For example:

● a = [8, 4.9, ‘hello!’]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.