UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Python- Basic Concepts part 1

Divya S.
12/01/2017 0 0

1. What is Python? 

  • Python is a high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence.
  • It is very popular and used by organizations such as Google, NASA, the CIA, and Disney.
  • Python is processed at runtime by the interpreter. There is no need to compile your program before executing it.
  • The three major versions of Python are 1.x, 2.x and 3.x. These are subdivided into minor versions, such as 2.7 and 3.3.
  • Python has several different implementations, written in various languages. CPython, is the most popular by far.

Ques 1. Python is a:

Ques 2. Which language is the implementation of python? 

2. Python Console- 

  • In this topic, we will start using Python, via the Python console. The first step is to download Python from www.python.org.
  • You should download the Python 3.x version that is compatible with your operating system. Once installed, the Python console can be accessed using one of several ways, including using the command line, running the Python interpreter directly, or running a GUI that comes installed with Python called IDLE.
  • After running IDLE, you should see a prompt of three right arrows. Type in "print('Hello world!')" and press enter. You should see the following: >>> print('Hello world!')
                                                                          Hello world!
  • The Python console is a program that allows you to enter one line of Python code, repeatedly executes that line, and displays the output. This is known as a REPL – a read-eval-print loop.
    After the "print('Hello world!')" line's output has been displayed, you can re-enter the code, and you will get the same output again. Try entering the same code, but with different text:

            >>> print('Hello world!')
                     Hello world!
            >>> print('Hello world!')
                    Hello world!
            >>> print('Spam and eggs...')
                    Spam and eggs...

  • When finished with the Python console, you will want to close it. You can close IDLE in the same way you close other programs on your operating system, but other kinds of consoles must be closed by different methods. To close a console, type in "quit()" or "exit()", after wrtiing your program and press enter.

Ques1. How to print "Hi"?

Ques2. How to print "ni ni ni"?

Ques3. What function closes python console?

3. Simple Operation

  • Python has the capability of carrying out calculations. Enter a calculation directly into the Python console, and it will output the answer.  

           >>> 2 + 2
                   4
           >>> 5 + 4 - 3
                   6

  • Python also carries out multiplication and division, using an asterisk to indicate multiplication and a forward slash to indicate division. 

           >>> 2 * (3 + 4)
                   14
           >>> 10 / 2
                   5.0

  • In python we follow the rule pf PEMDAS as like BODMAS in maths. Parentheses Exponential Multiplication Division Addition Subtraction.
  • Using a single slash to divide numbers produces a decimal (or float, as it is called in programming). We'll have more about floats in a later topic.
  • The minus sign indicates a negative number. Operations are performed on negative numbers, just as they are on positive ones. The plus signs can also be put in front of numbers, but this has no effect, and is mostly used to emphasize that a number is positive to increase readability of code.

           >>> -7
                   -7
           >>> (-7 + 2) * (-4)
                   20

  • Dividing by zero in Python produces an error, as no answer can be calculated. In Python, the last line of an error message indicates the error's type. Read error messages carefully, as they often tell you how to fix a program!

           >>> 11 / 0
           Traceback (most recent call last):
           File "", line 1, in
           ZeroDivisionError: division by zero

Ques1. What does this code output?
>>> 1 + 2 + 3

Ques2. What is output by this code?
>>> (4 + 8) / 2

Ques3. Fill in the blank to make this code correct.

>>> ( _ 5 - 1) * 3

-18

Ques4. What is the output of this code?

>>>(17+94)/(-5+5)

4. Floats

  • Floats are used in Python to represent numbers that aren't integers.  Some examples of numbers that are represented as floats are 0.5 and -7.8237591.
  • They can be created directly by entering a number with a decimal point, or by using operations such as division on integers. Extra zeros at the number's end are ignored.

           >>> 3/4
                   0.75
           >>> 9.8765000
                   9.8765

  • Computers can't store floats perfectly accurately, in the same way that we can't write down the complete decimal expansion of 1/3 (0.3333333333333333...). Keep this in mind, because it often leads to infuriating bugs!
  • As you saw previously, dividing any two integers produces a float. A float is also produced by running an operation on two floats, or on a float and an integer.

            >>> 8 / 2
                    4.0
            >>> 6 * 7.0
                    42.0
            >>> 4 + 1.65
                    5.65

  • A float can be added to an integer, because Python silently converts the integer to a float. However, this implicit conversion is the exception rather the rule in Python - usually you have to convert values manually if you want to operate on them.

Ques1. Which of these will not be stored as a float?

a) 7   b) 7.0  c) 2/4

Ques2. Output of this code.
>>> 1 + 2 + 3 + 4.0 + 5

         

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

What is the difference between PHP and PYTHON
Let's start with PHP: - Ideal for standard web development- Easy integration with MySQL- $_GET and $_POST built into the language- C-Esque syntax Primarily used on an Apache server (Routinely, you...

PEP (Python Enhancement Proposals)
Python Enhancement Proposals(PEP) are suggestions for improvements to the language, made by experienced Python developers. PEP 8 is a style guide on the subject of writing readable code. It contains a...

Python Script for random Password generation
from random import randintdef passwordgen(request): str_not_include = "1 L I i l o O 0" str_small ="abcdefghjkmnpqrstuvwxyz" str_caps = str_small.upper() str_num = "23456789" str_special...

File Handling in Python - Basic Concept
File (Flat) Handling in Python Types of files in python: 1: Text file: Stores data in the form of characters. Customarily used to store text/string data. 2: Binary file: Stores data in the form of bytes....

Decorator Advanced ( Passing Parameter )
Hope you read our previous note about the basic concept of python-decorators, if not, please read first Let see what are the possible ways to utilise the decorators in real time.Well, here we are going...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more