Posts

Showing posts from December, 2021

List, Tuple and Dictionary in Python

  Lists  A list is a sequence List Items List items are ordered, changeable, and allow duplicate values. List items are indexed, the first item has index  [0] , the second item has index  [1]  etc. List Length To determine how many items a list has, use the  len()  function: Example Print the number of items in the list: thislist = [ "apple" ,  "banana" ,  "cherry" ] print ( len (thislist)) Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in list are called elements or sometimes items . There are several ways to create a new list; the simplest is to enclose the elements in square brackets (“[" and “]”): [ 10 , 20 , 30 , 40 ] [ 'crunchy frog' , 'ram bladder' , 'lark vomit' ] The first example is a list of four integers. The second is a list of three strings. The elements of a list don’t have to be the same type. The following list contains a string

Variables, expressions, and statements in Python

Image
Installing Python To start programming with Python, you must be sure that python is well installed in your operating system. To install python on Windows; go to:  https://www.python.org / and download the latest version of python, the current version of python is 3.10.1. A fter your downloading finish, install python.   For those who are using Linux or MacOS they probably have already python. Then open your Terminal or Command Prompt and type: python or python3 If you have the same thing as shown in the picture above, this means python is well installed in your computer's OS. Reserved words in Python           Unlike human languages, the Python vocabulary is actually pretty small. We call this “vocabulary” the “reserved words”. These are words that have very special meaning to Python. When Python sees these words in a Python program, they have one and only one meaning to Python. Later as you write programs you will make up your own words that have meaning to you called variables .

Why should you learn to write programs?

       Writing programs (or programming ) is a very creative and rewarding activity. You can write programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem. This article assumes that everyone needs to know how to program, and that once you know how to program you will figure out what you want to do with your newfound skills. We are surrounded in our daily lives with computers ranging from laptops to cell phones. We can think of these computers as our “personal assistants” who can take care of many things on our behalf. The hardware in our current-day computers is essentially built to continuously ask us the question, “What would you like me to do next?” Programmers add an operating system and a set of applications to the hardware and we end up with a Personal Digital Assistant that is quite helpful and capable of helping us do many different things. Our computers are fast and have vast