Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Python An Introduction
Python An Introduction
Python An Introduction
Ebook98 pages28 minutes

Python An Introduction

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Python an Introduction.

Start learning Python and answer some questions to guage your knowledge on Python.

LanguageEnglish
Release dateOct 7, 2017
ISBN9780620774789
Python An Introduction

Related to Python An Introduction

Related ebooks

Programming For You

View More

Related articles

Reviews for Python An Introduction

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Python An Introduction - Renier Engelbrecht

    Chapter 1 - Introduction

    Python is simple language to understand as most of the commands are plain English. In this chapter, you are going to use Python to create simple scripts, in the interactive interpreter. An interpreted language is where the interpreter runs command for command, as opposed to a compiler language that takes all the code, compiles to byte code/executable and then runs the program. Therefore Python can have an interactive compiler, as Python is an interpreted language. The user enters a command in the interactive interpreter, and the command is executed. In this series the focus is on Python 3.4. There are two major versions of Python. The first is 2.7 and then there is 3.4. The difference is that 3.4 is the newest version that is to a major extend incompatible with code from 2.7. To maintain continuity and let developers make a transition to version 3, the older version is still supported. To use the newest version is better, as this contains all the new syntax and other enhancements.

    IDLE IDE

    The interactive Python Shell, as the screenshot above is called, is mainly used for short interactive sessions where the user want to write short amount of code, to test, debug(clear errors), or write specific procedures. In this chapter we focus on this interactive session. As soon as the Python IDLE Shell is closed, all data entered will be erased! Start Python IDLE. The shortest program that one can write is where the interpreter greets a person. For example; Hi there Sally! To do this, the user writes this in a print statement.

    Output

    In [3]:

    print ('Hi there Sally!') print (Hi there Sally!)

    Hi there Sally!

    Hi there Sally!

    The user entered a print statement. Take note of the following: all lower case the word print; and whatever the user want to displayed is between round brackets and single/double inverted commas. The user can use either double or single inverted commas to display the output or the message. The difference between the two is minimal and will be explained at later stage in detail. In this example, the user displayed a message, or output a message. Another interesting fact is that there are two commands. Each command starts on a new line!

    Activity 1

    Write a statement where the computer greet you showing your name.

    Write two statements where the compute greet you showing your name on one line and your surname on the next line.

    Variables

    Python is very good at storing of data. To store data, either storing, using or recalling data. In Python there are a few different types. However, for a start the focus is on numbers and text only. Other types will be focused on at a later stage.

    Numbers

    Python supports two types of numbers. The first is integers (7, 10, 12, 20000) and floating point numbers.

    Integers

    To define integers, assignments are used:

    In [4]:

    myvalue=1 anothervalue=2 someintegervalue=20000

    To view the content of the variables use the print statement.

    In [16]:

    print (myvalue) print (anothervalue) print (someintegervalue) print (myvalue, anothervalue)#Here we display more than one variable

    1

    2

    20000

    1 2

    The output displays the values of the integers.

    Float

    Assignment to float values are the same as with integers.

    In [17]:

    floatvalue = 1.3 anotherfloatvalue = 15.45 thirdfloatvalue = 123.64323

    To view the contetnt of

    Enjoying the preview?
    Page 1 of 1