Python Beginner Guide
----------------------------------------------------------------------
it a great choice for beginners and experts alike. Python's readability makes it a great first programming language — it allows you to think like a programmer and not waste time with confusing syntax. ... If Python isn't installed, it's easy to download and install. That's why i write this tutorial Introduction Python is a interpreted, object-oriented, high-level programming language.
Python was created by Guido van Rossum and officially released in the year 1991.
This language is still quite new and is one of the easier languages to learn.
Another really great thing about python is that unlike many programming languages, it does NOT require a semi-colon(";") at the end of every line.
• Python comes pre-installed with Mac OS X and
Linux.
• Windows binaries from
http://python.org/ • You might not have to do anything!
Rich, built-in collection types:
Lists
Tuples
Dictionaries (maps)
Sets
How to Install Python on Windows How to Install Python IDE ?
Below is a step by step process on how to download and install Python on Windows
1) To download and install Python, visit the official website of Python
https://www.python.org/downloads/ and choose your version.
2) Once the download is completed, run the .exe file to install Python. Now click on Install Now.
3) You can see Python installing at this point .
Good example of scripting language
“Pythonic” style is very concise
Powerful but unobtrusive object system
Every value is an object
Powerful collection and iteration
abstractions
Dynamic typing makes generics easy
simplified syntax and not complicated,
which gives more emphasis on natural language.
It is used in web development, data science, creating software prototypes and so on.
Fortunately for beginners, Python has simple easy-to-use syntax. This makes Python an excellent language to learn to program for beginners
Table of contents - Getting started
- Variables
- Operators
- Logical Statements
- Lists
- Loops
- Functions
- Modules
- Global Variables
- Final words & Credits
----------------------------------------------------------------------
Getting started I recommend you download and install Python, since Python 2.7 is outdated.just download Python 3
If you want to write your own Python programs, you need to use an IDE many begineers dont know full name of ide so full name is = integrated Development Environment
There are a lot of different IDE's for python, personally i prefer PyCharm.
If you are not yet familiar with python, i recommend you use JetBrains PyCharm Edu, which you can download for free
here.
This version of PyCharm offers you a diversity of tutorials, aswell as extra help features.
If you are familiar with python already, i recommend you use JetBrains Pycharm Community Edition, which you can download for free
here.
This version of PyCharm offers you alot more plugins and features.
In python you can add a comment to your code using the hash symbol ('#').
Example:
If you wish to have multiple lines of comments, you can enclose the lines of comments using the double quote symbol 3 times.
Example:
Code:
"""
These
Are
Multiple
Lines
Of
Comments
"""
Comments will always be ignored by the interpreter and are usually used to add some notes to a part of the code. (if u complete 1 project and you have to work after 2 months or long time that notes will helping to understand how you create that things )
----------------------------------------------------------------------
Python TUPLE - Pack, Unpack , Compare, Slicing of Tuple , Tuples and dictionary , tuples as keys in dictionaries What is Tuple Matching in Python?
-Tuple Matching in Python is a method of grouping the tuples by matching the second element in the tuples. It is achieved by using a dictionary by checking the second element in each tuple in python programming. However, we can make new tuples by taking portions of existing tuples.
Tuple Syntax Code:
Tup = ('Jan','feb','march')
To write an empty tuple = tup1 = ();
For writing tuple for a single value, you need to include a comma like = Tup1 = (10,);
Tuple indices begin at 0, and they can be concatenated, sliced and so on
Packing and Unpacking : In packing, we place value into a new tuple while in unpacking we extract those values back into variables
Code:
x = ("xyz99", 20, "imm") # tuple packing
(company, emp, profile) = x # tuple unpacking
print(company)
print(emp)
print(profile)
Comparing tuples comparison operator in Python can work with tuples
comparison starts with a first element of each tuple. If they do not compare to =,< or > then it proceed to the second element and so on
#case 1
Code:
a=(5,6)
b=(1,4)
if (a>b):print("a is bigger")
else: print("b is bigger")
#case 2
Code:
a=(5,6)
b=(5,4)
if (a>b):print("a is bigger")
else: print ("b is bigger")
Case1: Comparison starts with a first element of each tuple. In this case 5>1, so the output a is bigger
Case 2: Comparison starts with a first element of each tuple. In this case 5>5 which is inconclusive. So it proceeds to the next element. 6>4, so the output a is bigger
tuples as keys in dictionaries tuple is a hashable value and can be used as a dictionary key. A tuple would be useful as a key when storing values associated with a
grid or some other coordinate type system.
Example: We would come across a composite key if we need to create a telephone directory that maps, first-name, last-name, pairs of telephone numbers, etc. Assuming that we have declared the variables as last and first number, we could write a dictionary assignment statement as shown below:
Code:
directory[last,first] = number or other value or string
Inside the brackets, the expression is a tuple. We could use tuple assignment in a for loop to navigate this dictionary.
Code:
for last, first in directory:
print first, last, directory[last, first]
This loop navigates the keys in the directory, which are tuples. It assigns the elements of each tuple to last and first and then prints the name and corresponding telephone number.
Tuples and dictionary Dictionary can return the list of tuples by calling items, with each tuple is a key value pair
Code:
a = {'x':100, 'y':200}
b = list(a.items())
print(b)
Deleting Tuples Tuples are immutable and cannot be deleted. You cannot delete or remove items from a tuple. But deleting tuple entirely is possible by using the keyword = ' del '
Slicing of Tuple To fetch specific sets of sub-elements from tuple or list, we use this unique function called slicing. its also used for array and list.
Code:
x = ("x", "y","z", "f", "g")
print(x[2:4])
The output of this code will be ('z', 'f').
----------------------------------------------------------------------
Variables In python, variables are what you use to store values.
The three most important variables in python are:
An integer (int) is a variable where you can store a number that can be written without a fractional component.
check blank box for check content or go to google and search about it
Spoiler:
A float is a variable where you can store a number that is written with a fractional component.
Spoiler:
a = 80.42
b = -50.99
c = 0.000
An string is a variable where you can store characters if you enclose them in quotes.
Python treats single quotes the same as double quotes.
Example:
Spoiler:
a = "Hello"
b = "World"
c = "Cyberjagu"
----------------------------------------------------------------------
Operators Python has a lot of different operators, such as
mathematicial operators and
comparison(logical) operators.
Here is a list of some of the mathematical operators python uses. This operator adds the value's on both sides of the operator.
Spoiler:
This operator substracts the value on the right side of the operator from the value on the left side of the operator.
Spoiler:
This operator multiplies the values of on both sides of the operator.
Spoiler:
This operator divides the value on the right side of the operator by the value on the left side of the operator.
Spoiler:
This operator divides the value on the right side of the operator by the value on the left side of the operator
and returns the remainder.
Spoiler:
Here is a list of some of the comparison operators python uses.
These are the operators you will be using when you are working with while statements and for loops etc. If the value of both operands are equal, then the condition becomes true.
Spoiler:
if a == b:
print("a is equal to b")
If the value of both operands are not equal, then the condition becomes true.
Spoiler:
if a != b:
print("a is not equal to b")
If the value of the left operand is greater then the value of the right operand, then the condition becomes true.
Spoiler:
if a > b:
print("a is bigger then b")
If the value of the left operand is less then the value of the right operand, then the condition becomes true.
Spoiler:
if a < b:
print("a is smaller then b")
If the value of the left operand is equal to or bigger then the value of the right operand, then the condition becomes true.
Spoiler:
if a >= b:
print("a is equal or bigger then b")
If the value of the left operand is equal or less then the value of the right operand, then the condition becomes true.
Spoiler:
if a <= b:
print("a is equal or smaller then b")
----------------------------------------------------------------------
Logical Statements Logical statements are
also known as if/else statements.
They are statements that check whether the conditions are true or false.
In these statements we are going to use the comparison operators we just discussed.
A common mistake i made when i started out with Python was forgetting to add the ':' after the If statement line.
Don't forget to add this, if you don't the statement won't work and you will get an _error_.
Example:
Code:
a = 10
b = 10
if a == b:
print("a is equal to b")
else:
print("a is not equal to b")
If you run this code it will print "a is equal to b", because both variables are 10.
Example of a slightly more complicated if statement:
Code:
a = 10
b = 10
c = 20
isittrue = True
if a == c:
isittrue = True
elif a == b:
isittrue = True
else:
print("A is not equal to b or c")
isittrue = False
if a == b or a == c:
isittrue = True
else:
print("A is not equal to b or c")
isittrue = False
if a == b and isittrue == True:
c = c - b
print(c)
The first If statement checks if a is equal to c or if a is equal to b. Since a is equal to b, the variable isittrue will be set to True.
While this is a correct code, programmers are lazy people and always strive to make their code as short as possible.
That's why the second If statement checks exactly the same as the first if statement, but uses the or operator instead.
This way the or operator saves 2 lines of code, which in this case shouldn't matter alot, but if you are coding a big program, efficient coding will save you alot of time.
The third If statement checks if a is equal to b and if the variable isittrue is set on True.
If this is both the case (which it is), c will be set to be c - b.
Basicly what happens is the variable c is now 20 - 10.
After that the print statement will show 10 as the new value of the variable c.
----------------------------------------------------------------------
Lists Lists are a very important part of python.
A list is a variable that holds multiple values. A list in Python is similar to an array in Java.
You can declare a list the same as any other variable, except that it needs to be enclosed with brackets ("[]") and seperated with commas(",").
It's very important to remember that lists work with positions.
The first position is always 0, NOT 1
Example:
Code:
list = ["One", "Two", "Three"]
print (list)
print(list[0])
print(list[1])
print(list[2])
When you run this code, you will get this output:
Code:
["One", "Two", "Three"]
One
Two
Three
You might wonder what just happened, well:
Print (list) tells python to print everything that is in the list, which is why the commas and brackets get printed aswell.
Print (list[0] tells python to print the first variable in the variables list.
Print (list[1] tells python to print the second variable in the variables list.
Print (list[2] tells python to print the third variable in the variables list.
You might wonder why or how this could be usefull. I will get back to that later in this guide.
----------------------------------------------------------------------
Loops In Python there are several kinds of loops.
Right now we will discuss the two most important ones.
While loop This is one of the easiest and most basic loops of python. What a while loop does, is perfor a series of events as long as something is in a certain condition.
With the while loop you also need to add the colon sign after the line (':')
Example:
Code:
a = 5
while a > 0:
print (a)
a = a - 1
print("We are out of the loop!")
As you can see first we declare a variable, and then the while loop checks if the variable is bigger then 0.
This while loop will keep running the events within it until a is equal to 0.
So your output will be:
Code:
5
4
3
2
1
We are out of the loop!
You can use all comparison operators in a while loop to get the result you want.
For loop A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
The for loop is slightly more complex then the while loop, but it's still perfectly understandable.
The for loop executes a sequence of statements multiple times.
With the while loop you also need to add the colon sign after the line (':')
Let me explain this loop with an example.
Code:
for x in range(5):
print (x)
Or
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
(try it your self :D)
If you run this code your output will be:
The for loop goes through every item in a list before it can exit the loop.
In this example "x" is a variable. It does not have a set value, because it's used to run the for loop.
In simple terms: for x in a list with a range of 5, print x
Now you might be wondering, why does it stop at 4, when we said range 5?
You have to remember, that a for loop works with lists, and as mentioned before, the first position of a list is 0.
----------------------------------------------------------------------
Functions Functions are very important when you are coding a program or script.
A function is in simple terms a specific piece of code.
A function is very efficient when you need to run a function multiple times, for example in a loop.
Here a simple example of a define:
Code:
def definitionname():
print("This is my define.")
definitionname()
The "def" is how you start the definition. After that you put in a unique name for your definition. This can be anything you like.
With the define you also need to add the colon sign after the line (':')
If you want to run the code within the define, you can call it by typing the name of the function with parameters ("()")
The output for the code above would be: This is my define.
As mentioned before a function is especially efficient when you want to run the code in the function multiple times.
For example:
Code:
def multipletimes():
print ("My very first define.")
for x in range(5):
multipletimes()
When you run this code your output will be:
Code:
My very first define.
My very first define.
My very first define.
My very first define.
My very first define.
This is a very simple example, but you can already see how efficient it is.
This way the print statement is executed 5 times, with only 4 lines of code.
When you are coding a complex program or script defines will make your job a lot easier!
----------------------------------------------------------------------
Modules Modules are python programs that you can use.
These mudules are scripts written by another person in order for you to be able to make a fairly complex script/program, without extensive knowledge about the functions you are using.
To be able to use a module, you first have to import it. You can simply do this by typing 'import' and the Python module name.
For example:
Time is a basic Python module that is included in the standard python package you downloaded at the start of this thread.
You are now able to use this module.
A simple example of how you can use the time module:
Code:
import time
seconds = time.time()
print("number of seconds since 10:00am, Januari 1 1970:", seconds)
When you run this code the output will be something like:
number of ticks since 10:00am, Januari 1 1970: 1457813005.3186388
You are probably thinking: How can i know every single module name and every statement within a module?
The answer to that is simple. Google what you need! For example, if you want to make a running clock, you can google: Python clock.
In the results you will most likely find a site such as stackoverflow. On this site it will probably tell you that in order for you to make a clock in python, you need to import the time module.
----------------------------------------------------------------------
Global Variables At last i want to explain what global variables are and what you can use them for.
First of all, try to avoid global variables as much as possible! With big scripts it would get really messy really quik.
That being said, a global variable is a normal variable, not unlike the normal variables we discussed earlier in this thread.
The difference between normal variables and global variables is that global variables are being used within loops and statements.
For example:
Code:
x = 10
def normalx():
x = 5
normalx()
print (x)
def globalx():
global x
x = 20
globalx()
print (x)
In this example we declare the variable x as 10.
Then we run the function normalx, and after the function has been ran we print x.
Then we run the function globalx, and after the function has been ran we print x again.
When you run this code your output will be:
The reason for this is that in the first define, x is not called as the global x.
In the second define we do call x as global x, which is why the global x variable has been changed from 10 to 20.
recommendations Whenever you are stuck, either look up
https://tutorialspoint.com and go to the python tutorial, or look for solutions on stackoverflow. Smart googling will most likely yield stackoverflow results whenever python is mentioned.
For applying and honing your programming skills:
check out these python modules and play around with them a little
For install them
Use = pip forwindows or pip3 for linux or mac
Open your terminal ==> pip/pip3 install sockets(modual name)
socket
socks
selenium
pyppeteer
requests
many users apply for Full Membership (i think its usefull for them I can't write everything related to challange This is just a Guideline
I am not even tell everything will be done by using this, I am just giving you an idea )
the first two are modules for internet and OS internal communications via a concept called socket. all internet communication is based upon sockets and their operations (except for wifis and some layers of LANs). If you can master sockets, then you can build basic web servers or other services, like building your own communication networks, botnets, whatever needs communicatin'
socks is a socket-esque module that supports socks4 and socks5 proxies, this is very useful for communication via tor.
selenium and pyppeteer are two modules that allow you to automate a web browser, allowing you to automatically click buttons, fill out forms and so on. you can use this for creating mass email accounts, writing social media comments or, and this is my main metier, trading bots (or at least it used to be, way back in the day before I caught wind of trading APIs), I for instance wrote a bot that logged into and controlled btc accounts on it's own using selenium. these complex tasks are a bit hard to do with sockets or requests, because most web apps are highly complex and use hundreds of requests and forms for things that just appear to be one single button.
requests, the online python communities favorite, is a module to automate http requests. that's it.
there are also various cryptography libraries out there featuring the current algorithms. feel free to write your own password manager as a simple CLI
Many moduals are available Just search it (google is your Friend)
----------------------------------------------------------------------
Final words & Credits Congratulations! You have finished this python tutorial!
Right now you know the basics of Python.
Right now you are thinking: Hmm alright it was fun and all, but what do i do now with my knowledge?
Simple! Practice with Python. You can code a variety of programs and scripts, from a logger to an email bomber to battlefield 2.
Ofcourse coding in python still requires some effort, but if you ever run into trouble, feel free to shoot me a PM.
I will always be available to answer all questions regarding Python.
Credits: Some Online research and some forum
If you have found any mistakes in this tutorial, please notify me and i will edit it as soon as possible. Happy programming!
You know that I have worked hard in this, so a good comment of yours will help me to post similar tutorials.
Cyberjagu.