Introduction To Python [Day 13 ]

Introduction To Python [Day 13 ]

1. What is Python

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.

It is used for:

  • web development (server-side),

  • software development,

  • mathematics,

  • system scripting.

2. Usage Of Python

  • Python can be used on a server to create web applications.

  • Python can be used alongside software to create workflows.

  • Python can connect to database systems. It can also read and modify files.

  • Python can be used to handle big data and perform complex mathematics.

  • Python can be used for rapid prototyping or production-ready software development.

3. Benefits Of Using Python

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).

  • Python has a simple syntax similar to the English language.

  • Python has a syntax that allows developers to write programs with fewer lines than some other programming languages.

  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.

  • Python can be treated procedurally, in an object-oriented way or in a functional way.

  • Python was designed for readability and has some similarities to the English language with influence from mathematics.

  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.

  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly brackets for this purpose.

4. How to Install Python In Windows and Linux?

a) For Windows Installation you can go to Python's official website python.org/downloads and Download Python 3.11.3 version (latest version)

b) Python version is 3.12.

c) You also can Install Visual Studio code to run Python script in an easy way , as in VS Code there Pyhton extension is also available which makes writing very easy.

d) From this website you can download code.visualstudio.com/download VS code as per your requirement.

5. Example of a Simple Python Program::

  1. Like in every programming language we always start by executing a simple "Hello World" Program :

print ("Hello World")

Output

Hello World

Print is a built-in function and inside the () it is a string that can be enclosed by '' quotes, double '' '' quotes

  1. The sum of two numbers:

    a= 20

    b= 30

    sum= a+b # Add the two numbers

    print("The sum of the two numbers is :",sum) # Display the sum

Output

The sum of the two numbers is 50

6. Different Data Types In Python

  • 1 Numeric Data Type:

    Int: holds signed integers of non-limited length.

    Float: holds floating decimal points and it's accurate up to 15 decimal places.

    Complex: holds complex numbers.

    We can use the type() function to know what is the data type.

    Example:

    Output

  • 2 List Data Type:

    A list is an ordered collection of similar or different types of items separated by commas and enclosed within brackets [ ].

    Example:

    To access items from a list, we use the index number (0, 1, 2 ...).

  • 3. String Data Type:

    The string is a sequence of characters represented by either single or double quotes.

    Example:

  • 4. Set Data Type:

    The Set is an unordered collection of unique items. Set is defined by values separated by commas inside braces { }.

  • 5. Dictionary Data Type:

    Python dictionary is an ordered collection of items. It stores elements in key/value pairs. Keys are unique identifiers that are associated with each value.

    Here keys are Nepal, Italy, and England and Values are respectively Kathmandu, Rome, and London.

  • 6. Tuple Data Type

    Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.

    We use the parentheses () to store items of a tuple.

    These are some important data types to remember while working with Python.