Basics Of List | Development | Online Course With Appy Pie Academy

Basics of List

Lesson Details:
June 29, 2020


I: Introduction

A: Learn basic python programming for beginners

I strongly believe that Python as a language is easy to learn and understand. The syntax of the language is clear and concise, and it is quite straightforward to write any program in Python.

Python is a high-level programming language that was created by Guido van Rossum in 1991. Python is an interpreted language, which means that the program is not compiled into machine language and has to be run through an interpreter program. Unlike C and C++, Python does not require any pre-processing before running the program through the interpreter.

There are advantages of using this language for developing applications or web services. It offers multiple ways of solving a problem and supports integration with other languages such as C++, Java, etc. It also offers a wide range of libraries, frameworks, and tools that can be used for different purposes.

A: Basics of list

List is a data structure which contains a collection of elements. Each element has a unique index. Lists can be accessed by index, which means they are considered as ordered data structures. Lists are dynamic in nature as they allow adding or removing elements from them at runtime.

In Python, lists are mutable data types. In other words, you can change the elements of a list as required as there is no restriction on modification of a list as compared to other data types such as strings or integers. You can insert or delete elements from a list, reorder its elements at runtime, etc.

List comes with a number of built-in operations that help you to manipulate lists easily. Some of these operations include sorting a list by one or more keys, copying a list so that you can use it in your program without modifying its original data type, etc. This section will cover the basics of creating and manipulating lists in Python.

Creating a list: In Python, you can create an empty list with the following statement: lst = [] In order to create a list with some values, you can use the following statements: lst = [] lst = [1, 2, 3] lst = ["a", "b", "c"] lst = range(0, 100) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 #!/usr/bin/python3 # -*- coding: utf-8 -*- """ Created on Sat Nov 5 16:16:00 2017 @author: Javed """ n = 0 print ( "Enter the total no of numbers :" ) total = int ( input ( ) ) def addNumbers ( ) : result = "" for i in range ( 0 , total - 1 , 2 ) : result = str ( i ) + " + " + str ( i + 1 ) + " = " + str ( result ) print ( result ) def subNumbers ( ) : result = "" for i in range ( 0 , total - 1 , 2 ) : result = str ( i ) + " - " + str ( i + 1 ) + " = " + str ( result ) print ( result ) def mulNumbers ( ) : result = "" for i in range ( 0 , total - 1 , 2 ) : result = str ( i ) + " * " + str ( i + 1 ) + " = " + str ( result ) print ( result ) def divideNumbers ( ) : result = "" for i in range ( 0 , total - 1 , 2 ) : result = str ( i ) + " / " + str ( i + 1 ) + " = " + str ( result ) print ( result ) def main ( ) : while True : print ( "ttttttttttttt" ) chooseOperation = input ( "Choose what you want to do" ) if chooseOperation == "Add" : addNumbers () elif chooseOperation == "Subtract" : subNumbers () elif chooseOperation == "Multiply" : mulNumbers () elif chooseOperation == "Divide" : divideNumbers () else : print ( "Wrong Choice" ) main ( ) #!/usr/bin/python3 # -*- coding: utf-8 -*- """ Created on Sat Nov 5 16:16:00 2017 @author: Javed """ n = 0 print("Enter the total no of numbers :") total = int(input()) def addNumbers(): result="" for i in range(0, total - 1, 2): result=str(i) + " + "+str(i+1) +"="+str(result) print(result) def subNumbers(): result="" for i in range(0, total - 1, 2): result=str(i) +" - "+str(i+1) +"="+str(result) print(result) def mulNumbers(): result="" for i in range(0, total - 1, 2): result=str(i) +" * "+str(i+1) +"="+str(result) print(result) def divideNumbers(): result="" for i in range(0, total - 1, 2): result=str(i) +" / "+str(i+1) +"="+str(result) print(result) def main(): while True: print("ttttttttttttt") chooseOperation=input("Choose what you want to do") if chooseOperation=="Add": addNumbers() elif chooseOperation=="Subtract": subNumbers() elif chooseOperation=="Multiply": mulNumbers() elif chooseOperation=="Divide": divideNumbers() else: print("Wrong Choice") main()

Output:

loader
Course content