Chp:->2 Python <-> More Python

Prince

[ Verified Seller ]
Staff member
Trusted Seller
Joined
11 yrs. 6 mth. 26 days
Messages
5,381
Reaction score
18,380
Age
45
Wallet
11,590$
Chapter -- > 2 :~# More python

#2.1 --|Numbers|--

Python is just like powerful language such as C and java, supports 3 data types for scientific calculations. The three DATA TYPES are :

1. Integer
2. String
3. Boolean

+================================================================+

#2.2 --|Variables|--

In python language, Variables needn't declared.
You can call them right from where you need them!

For instance
Variable can be assigned by just simply typing x = 6
But in other lanugages such as C++
You have to declare variable as follows;
Quoteint x;

Another example

>>>x = 3>>>y = 3>>>print(x*y)9
First variable x is assgined integer 3
Then variable y is assgined integer 3
After that, print function is used to output the results.
Now you should have grub the basics of variable :D

+===============================================================+

2.3# --|Functions|-- (General)

Now we're going to talk about functions briefly
Functions are vital in every programming lanugages.
You can define your own function or use the existing function.
Function is sort of like a feature, for example "pow(x,y)" is a function.
Functions can help make your program more powerful and as well as making your program easier to maintain!

In C++ when writing functions (not very sure :D)
1. Definiation must be first declared
2. Write the defination
3. Call the Definination
are bound to be followed.

+==================================================================+

2.4# --|Modules|-- (General)

You may have realized the import statement  above some of the programs.
Eg. import math
Import is a command that import the modules into the program.
Modules can make program more powerful.
We'll come to modules later...

+==================================================================+


2.5# --|Comments|--

If you have tried any one of programming language, you would have heard about comment definately. Every programming language has it's own style of writting comments.
For example, Comments in C language is indicated by /* comment */
In python you just need to use sharp sign "#"#!usr/bin/env python#This is a commentPrint(‘hello’)#This is a comment again

Interpreter will not execute the string/code after # sign, it knows that it's a comment, and simply skips. Commenting makes the program more readable and easier to debug.
We'll go into details about writing functions in next chapter.

Commonly used Functions
1.print()
2.input() / raw_input()
2.float
3.complex

Example, 1, 2, 3, 4 are integers.
Python do not have long integer type as C language. It's included in integer type.
This might be a weakness.

6.39 and 787.6E-9 is float data type.
787.6E-9 = 787.6*10-9

It also supports complex number that are commonly used in Mathematics.
Example 9+7j

Now we'll deal with number operatoin. #OpNo :D
Open up Python shell. Let's get started.

>>> 1+12>>>1/20
Now why 1 divided by 2 didn't result in 0.5?
Because Python took it as integer. But it's not the problem anymore in python version 3.

>>>1.0/2.00.5
In this way, we can calcualte basic Arithmetic Operations, such as addition, subtruction, multiplication, and division.
“+ - / *”
Another one
>>>1%2
"%" operator is used to calculate remainder of a division.

Quote
>>>3**2
9
"**" means power

>>>-3**2
-9
>>>(-3)**2
9
Latest version didn't have the buffer overflow anymore!
Hexadecimal and Octal are also supported

Quote
>>>0xCD
205

Hex form is 0xXX
>>>010
8
This is ocatal, but in version 3 it changed to following

>>>0o10
8

Now, we've reached the end of Chapter 2 :D

Thanks for reading.
Ref : Multiple Sources
MrGeek @ Z+ :-> logout
 
Top Bottom