Python programming basic

  

https://cccabs-service.in/blogs/python-ascending-order-and-decending-of-list-items

Welcome to Python Programming Tutorial!

Python is a high-level, interpreted, and general-purpose programming language. It was first released in 1991 by Guido van Rossum and has since become one of the most popular programming languages in the world. It is widely used for web development, data analysis, artificial intelligence, and scientific computing.

In this tutorial, we will cover the basics of Python programming, including data types, control structures, functions, modules, and more. So, let's get started!

Getting Started

Before we begin, you need to install Python on your computer. You can download the latest version of Python from the official website: https://www.python.org/downloads/

Once you have installed Python, you can open the Python shell by typing "python" in your terminal or command prompt. This will open up a prompt where you can start typing Python code.

Data Types

Python supports several data types, including numbers, strings, lists, tuples, sets, and dictionaries.

Numbers

Numbers in Python can be of two types: integers or floating-point numbers. To declare an integer variable, you can simply assign a value to a variable:

x = 5

To declare a floating-point variable, you can use a decimal point:

y = 3.14

Python also supports complex numbers:

z = 3 + 4j

Strings

Strings in Python are used to store text data. They can be declared using single quotes or double quotes:

name = 'John' message = "Hello, World!"

You can also use triple quotes to declare multi-line strings:

paragraph = """ This is a multi-line string in Python. """

Lists

Lists in Python are used to store collections of data. They can contain any type of data, including other lists. To declare a list, you can use square brackets:

numbers = [1, 2, 3, 4, 5] fruits = ['apple''banana''cherry']

Tuples

Tuples in Python are similar to lists, but they are immutable, meaning that their values cannot be changed once they are declared. To declare a tuple, you can use parentheses:

coordinates = (1, 2)

Sets

Sets in Python are used to store unique values. To declare a set, you can use curly braces:

numbers = {1, 2, 3, 4, 5}

Dictionaries

Dictionaries in Python are used to store key-value pairs. To declare a dictionary, you can use curly braces and colons to separate keys and values:

person = {'name''John''age'30}

Control Structures

Python supports several control structures, including if/else statements, while loops, and for loops.

If/Else Statements

If/else statements in Python are used to control the flow of the program based on certain conditions. Here is an example:

x = 5 if x > 0print("Positive"elseprint("Non-positive")

While Loops

While loops in Python are used to execute a block of code repeatedly while a certain condition is true. Here is an example:

x = 0 while x < 10print(x) x += 1

For Loops

For loops in Python are used to iterate over a sequence of values, such as a list or a string. Here is an example:

fruits = ['apple''banana''cherry'] for fruit in fruits:

Python ascending order and decending of list items

 # make a custom ascending order of list item and
# decending order of list item

li = [20, 50, 100, 3, 30, 13]

def ascendingOrderList(li):
    count = 0
    while count < len(li):
        for i in range(1, len(li)):
            if li[i-1] > li[i]:
                li[i], li[i-1] = li[i-1], li[i]
        count += 1
    return li

print(ascendingOrderList(li))

def decendingOrderOfList(li):
    count = 0
    while count < len(li):
        for i in range(1, len(li)):
            if li[i-1] < li[i]:
                li[i], li[i-1] = li[i-1], li[i]
        count += 1
    return li

print(decendingOrderOfList(li)) 
more examples please checkout this link

Comments

Popular posts from this blog

Python Programming tutorial and exercise

Open AI integration using python