Python Guide Part I

November 20, 2016 | Views: 8011

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Python Guide

Python is a programming language that lets you work quickly and integrate systems more effectively. The standard library of python has its documentation which is available, as it the case for tutorials and guides. The source code and installers are available for download for all versions. The latest version is Python 3.5.2.

Running Python

First Program

-Python 3 Interactive Interpreter
>>>print ('Hello world')
Hello world
>>>

 

-Python Files
print ('Hello world')
#save as hello.py then type on the terminal python3 and path/of/the/python/file.py

 

-On UNIX
#!/usr/bin/python3
print ('Hello world')

Simple built-in data types

booleans (which have the value True or False ). integers (whole numbers such as 42 and 100000000 ). floats (numbers with decimal points such as 3.14159 , or sometimes exponents like 1.0e8 , which means one multiplied by ten to the eighth power, or 100000000.0 ). strings (sequences of text characters).

Variables, Names, and Objects

-All is an object in Python; float, Booleans, data structures and functions also are implemented as an object.

Variable


>>>a=7
7
>>>

>>>type(a) #to know the type of anything
<class 'int'>
>>>int(98.8)#type conversion
98
>>>float('98')
98.0

Name
Must begin with a character, and you can within it digits and the underscore. Avoid this: _var1, 1var

Arithmetic Operators and Bases

#Arithmetic Operators
-Addition: +
>>>5+3
8
>>>
-Subtraction: -
>>>5-3
2
>>>
-Multiplication: *
>>>5*3
15
>>>
-Floating point division: /
>>>5/3
1.6666666666666667
>>>
-Integer division: //
>>>5//3
1
>>>
-Modulus: %
>>>5%3
2
>>>
-Exponentiation: **
>>>5**3
125
>>>

#Bases
0b for binary
0x for hex
0o for octal

>>>0b10
2
>>>
Expressions

-It’s like in the other languages:

a+b
a+=b
a/=b
‘a’+’b’

With the same order of precedence.


That’s all, and thanks! Comment below to ask me any questions or let me know how I can improve.

Share with Friends
FacebookTwitterLinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterLinkedInEmail
Ready to share your knowledge and expertise?
12 Comments
  1. My friend that will be a pleasure but my advice as beginner like you try it by your own.. hustle, percever and you will be the best. That’s what am trying to do :)))))))

  2. thanhs am just a beginner in programming can you be my personal tutor. email me@:maliksunday592@gmail.com

Page 2 of 2«12
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel