Website Tutorial and Download Program, Design, And News Technology and Lifestyle. We Have Free Download Source Code Project and Update Tutorial. We Sharing For Learning.

Tutorial programming phyton basic

tutorial phyton programming


Interactive Mode


We can start running the Python interactive mode (command line interpreter) and immediately start writing the program code. EaInteractive Mode We can start running the Python interactive mode (command line interpreter) and immediately start writing the program code. Each operating system must have a command-line intrepeter, e.g. on Windows we know DOS, whereas on Linux we knowShell. This mode is very help us in testing some of the features of Python. ch operating system must have a command-line intrepeter, e.g. on Windows we know DOS, whereas on Linux we knowShell. This mode is very help us in testing some of the features of Python.

On the Linux operating system, we can run this mode by using the Terminal. Because Python is a programming language that is already integrated with Linux, then we simply write python on shell prompt.

$ python

By typing python at the shell prompt, we will go into interactive mode Python thatwill be marked with "> > >".


Script Mode


We can also run Python scripts directly by executing a program on the shell prompt. We simply write a command:


$ python programKu.py

This command will execute the programKu.py script directly from Active Directory now.

We make first programKu.py, and then save the file in the working folder. In writing the code of programKu.py, we can use the Text Editor that has been provided by Linux, such as gEdit or Geany. The writer has always been to use Geany. The following code listing programKu.py:


# file: programKu.py

print "Python, Saya Datang!"




Mode IDLE


Python can also be run on graphics mode called mode IDLE. Tkinter-based, which is IDLE to run it we have to install Tcl/Tk. IDLE run directly from the folder/usr/lib/python2.7/idlelib/. The following display is IDLE:

The first program


In this section, we will learn how to write a program input/output and display a comment according the rules of language (syntax) of Python.

The first program that we will create is a welcome program. Type the following command line by using the interactive mode.


>>> print "Welcome to Python Programming"


The result of the above command is

Welcome to Python Programming

As we see, the print function to display the output on the screen. Program input (input) and output (output) is a very important basic features of any programming language. In Python, to program the outputs we can use the command print. As for the program's input, we use raw_input (). Raw_input () command only accepts input of type text. Refer to the following example:

> > > name = raw_input ("type Your name:")

This command will display a message asking Your name input.
Type your full name: Biggie Noviandi

It is time we will show the name that we've inserted by using the print command.
> > > print "your name is", the name of

COMMENTS


Most programming languages scripts use the fence (#) to start a comment. This comment is very important to clarify the meaning of the code we write. However, this comment will not be executed by the program alias disregarded. Not important forthe program but it is important for us. Here's an example comment:


> > > #ini first comment
... print "any longer learnt about the comment" second comment #ini

The output of the above command line:
Learn more about comments


USING VARIABLES IN PYTHON


All programming languages, including Python, use a variable to store the data in computer memory.


Unlike other programming, a variable in Python does not have to be declared explicitly. A declaration of a variable occurs automatically when we give a value to a variable. As programming languages in General, same-sign with (=) is used to provide avalue to a variable. The three on the left side of the sign (=) is the name of a variable, while the three that the right of the sign (=) is the value assigned to the variable.

> > > price = 100
> > > discount = 25
> > > price-discount 
75


In the above example, 100 and 25 is the value assigned to the variable pricing and discounts. While the statement the price-discount will calculate the difference between the discounted price. Variables can also store a value of text (a string).

> > > a = ' school '
> > > b = ' basic '
> > > a + b
' schoolbasic '


Variables can also store two or more string values by using the operator (+).

> > > c = ' Py ' + ' thon '
> > > c
' Python '

If we had put a value in a variable, we can use these variables in the expression of the other.

> > > a = 2
> > > a = a + 3
> > > a
5

We can also provide a values for some variables.

> > > p = q = r = 1
> > > p
1
> > > q
1
> > > r
1

In addition, we can also provide some value for some variables (called multiple assignment).


> > > x, y, z = 1, 2, ' learn Python '
> > > x
1
> > > y
2
> > > z

' Learning Python '
Another form of the above example, we can use the brackets-brackets-open lid.

> > > (x, y, z) = (1, 2, ' learn Python ')

Way above, can also we used to Exchange variable value.

> > > (x, y) = (10, 20)
> > > x
10
> > > y
20
> > > (x, y) = (y, x)
> > > x
20
> > > y
10

DATA TYPES IN PYTHON


Use the type Number

The Number data type used to hold numeric values. This type is immutable data types, which means that if we change the value of a data, then we will allocate a new object. Just like any other data type, the Number of objects created when we give a value to it. Example:


> > > data = 1



We can also change the value in the variable data.

> > > data = data + 1
> > > data = 3.50
floatdat > > > = 7.5
> > > data = floatdat

We can delete an object or many objects by using the statement del. For example:

> > > del data
> > > del data, floatdat

Python classifies the type of Number in 4 kinds, namely:


Plain Integer



Plain integer or integer is a data type that we often encounter in all programming languages. It had a range of integer values between-2 ^ 32 to 2 ^ 31-1. This type can also be written in octal form (sign prefix "0") or hexadesimal (marked the prefix "0 x" or "0 x"). Example:

10 100 6542-784
083-042-0X61 0x43

Long Integer


Long integer calculations help us greatly beyond the range integer value. Virtually, there is no limit on the value of a large virtual memory dependent that we use. The suffix ' l ' or ' L ' at each integer value indicates that the data type long integer.

562718819L-0x526718L 012L-567299101L

A Real Floating Point Number


This type is often referred to as type real (or float). This is the same type of type double in c. value of float has two parts, the part of the decimal point and exponential part. A positive or negative sign between the "e" is the sign of the exponent.Example: float value

0.0 14.5 15.4-32.3 + e18
-90.76712-90. -32.54 e100 70.2-E12

Complex Number


A complex number is usually shown by the form a + bj, where a is the real part and b is the imaginary part. The imaginary part is the number at the beginning of the mark "j" or "J". The following is an example of complex numbers:

3.14 j 45j 54.56 + 12.1 J 3e + 36J

The real and imaginary parts of complex numbers we can separate them using the data attribute, i.e. using real and imag. As for getting the conjugation of complex numbers, we can use the method of conjugate ().

> > > complex = 23.45 1.23-J
> > > real complex.
23.45
> > > imag site.
-1.23
> > > complex conjugate ().
(23.45 + 1.23 j)

1 Comment for "Tutorial programming phyton basic"

om cek facebook :v
Aku gak ada Hp :v

Back To Top