Python is the fastest growing language in terms of number of developers who are using it, the number of libraries it has, number of companies who are using it and in terms of areas to be implemented. If we talk about machine learning, GUI, software development, web development, it can be used everywhere and that’s why is it also called a general purpose language. It is a programming language which is interpreted, object-oriented high-level language. It also supports procedure-oriented programming depending upon the purpose you can use it the way you want. It came in 1989 which is the easiest programming language till now way much easier than JAVA, C++ or any other language. Reddit is purely written in python and there are many companies which are using python as a supportive language or as a main language like Google, NASA, etc. Guido Van Rossum has written this language. It is one of the easiest languages to learn.
Where should you start?
You can write a Python code anywhere even on a notepad but run a program we need to install an interpreter which is a Python interpreter. To install Python from the official website of Python which looks like something below:
On installing the setup the Python window will look like something below
Intro to Lists and Objectives
A List is a collection or grouping of items and those items could be string, float, integers. Boolean values or any other lists. It is a way of combining data into one data. Let’s say we want to make an app that has a shopping cart feature. So a user could add items to a shopping cart and keep track of those items. These are called arrays and in Python, these are called lists.
Behind the scenes, they are all stored in the exact same list.
Swapping values in the list
When do you need to swap – When you are shuffling things, sorting we are not making a new list.
We’ve already seen a few examples of methods when learning about Object and Data Structure Types in Python. Methods are essentially functions built into objects. Later on, in the course, we will learn about how to create our own objects and methods using Object Oriented Programming (OOP) and classes.
Methods perform specific actions on an object and can also take arguments, just like a function. This lecture will serve as just a brief introduction to methods and get you thinking about overall design methods that we will touch back upon when we reach OOP in the course.
Methods are in the form:
Let’s take a quick look at what an example of the various methods a list has:
In : # Create a simple list lst = [1,2,3,4,5]
Fortunately, with iPython and the Jupyter Notebook, we can quickly see all the possible methods using the tab key. The methods for a list are:
Let’s try out a few of them:
append() allows us to add elements to the end of a list:
In : lst.append(6) In : lst Out: [1, 2, 3, 4, 5, 6]
Great! Now, how about count()? The count() method will count the number of occurrences of an element in a list.
In : # Check how many times 2 shows up in the list lst.count(2) Out: 1
You can always use Shift+Tab in the Jupyter Notebook to get more help about the method. In general Python you can use the help() function:
In : help(lst.count)
A SIMPLE CODE TO WRITE PYTHON3