Posts

Showing posts from October, 2017

range() in python

Image
RANGE: The range() function returns of generates a sequence of numbers, starting from the lower bound to the upper bound.                            range ( lower_bound , upper_bound , step_size )  lower_bound: The starting value of the list. upper_bound: The max value of the list, excluding this number. step_bound: The step size, the difference between each number in the list. The lower_bound and step_size parameters are optional. By default the lower bound is set to zero, the incremental step is set to one. The parameters must be of the type integers, but may be negative. The lower_bound and step_size parameters are optional. By default the lower bound is set to zero, the incremental step is set to one. The parameters must be of the type integers, but may be negative. range implementation difference This distinction w...

arithmatic operator in python

Image
Operators are the constructs which can manipulate the value of operands. Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator Types of Operator Python language supports the following types of operators. Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators Let us have a look on all operators one by one. today we will talk about arithmetic operators ! ARITHMATIC OPERATORS : Assume variable a holds 10 and variable b holds 20, then Operator Description Example + Addition Adds values on either side of the operator.                          a + b = 30 - Subtraction Subtracts right hand operand from left hand operand.                ...

whatsapp group

Image
INTRODUCTION! greetings citizens of  the world hi ! I am anonymous and today I will invite you to our anonymous groups for learning hacking , programming , networking and it . we have every language programmer , white hat hacker , and networking experts . group was created by anonymous ! you can join and learn ! our slogan is " KNOWLEDGE IS POWER". I don't wanna say more about my group just come and check your own! and if you want to know what our group members think about our group just check comments on this post you will got it ! KNOWLEDGE IS POWER IT CANT BE LEARNED COMPLETELY ! BUT EXTENDED! AND WE DO IT !

loops in python

Image
LOOPS: Code can be repeated using a loop. Lines of code can be repeated N times, where N is manually configurable. In practice, it means code will be repeated until a condition is met. Python has 3 types of loops: while loops , nested loops and for loops. For loop We can iterate a list using a for loop   member = [ "Abby" , "Brenda , "Clindy" , "Diddy" ]   for i in member: print(i ) The for loop can be used to repeat N times too: for a   in range ( 1 , 10 ) :   print (a ) WHILE LOOP : If you are unsure how many times a code should be repeated, use a while loop. For example, correctNumber = 5 guess = 0 while guess != correctNumber:     guess = int ( input ( "Guess the number: " ) )     if guess != correctNumber:         print ( 'False guess' ) print ( 'You guessed the correct number' ) We can combine for loops using nesting...

scope in python

Image
SCOPE SCOPE: variables can only reach a area in which they are defined this is called scope in python. Think of it as the area of code where variables can be used . Python supports global variables and local variables. By default, all variables declared in a function are local variables. To access a global variable inside a function, it’s required to explicitly define ‘global variable’. Example Below we’ll see the use of local variables and scope. This code   will not work: def function (a ,b ) : print ( 'You called function(a,b) with the value x = ' + str (a ) + ' and y = ' + str (b ) )   print ( 'a * b = ' + str (a *b ) )   = 4 # cannot reach p, so THIS WON'T WORK p = 3 function(5 , 2 ) this example will not work the example down will work : def function (a ,b ) :     p = 3     print ( 'You called function(a,b) with the value a = ' + str ( x ) + ' and b = ' + str ( y ) ) ...

Global and local variables

Image
GLOBAL AND LOCAL VARIABLE

Functions in python

Image
FUNCTIONS statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. A function is reusable code that can be called anywhere in your program. Functions improve readability of your code: it’s easier for someone to understand code using functions instead of long lists of instructions. functions can also be re-used and modified so it also increases its testability. we use this syntax to define a function:                                         def function(parameters):                                 ...

variables

Variables can hold numbers that you can use one or more times. Numbers can be of one of these datatypes: integer  (1,2,3,4) float  (numbers behind the dot) boolean  (True or False) Numeric variables example Example of numeric variables: x = 1 y = 1.234 z = True You can output them to the screen using the print() function. x = 1 y = 1.234 z = True   print ( x ) print ( y ) print ( z ) Python supports arithmetic operations like addition (+), multiplication (*), division (/) and subtractions (-). #!/usr/bin/env python   x = 3 y = 8   sum = x + y   print ( sum ) User input Python 3 Use the input() function to get text input, convert to a number using int() or float(). #!/usr/bin/env python   x = int ( input ( "Enter x:" ) ) y = int ( input ( "Enter y:" ) )   sum = x + y print ( sum )

Strings in python

A string is a series of characters, they are mostly used to display text. To define a string simply type text between quotes. Python accepts single, double and triple quotes. String input and output To output text (string) to the screen: s = "hello world" print ( s ) To get text from keyboard: name = input ( "Enter name: " ) print ( name ) If you use an  old Python version (2.x) , you need to use: name = raw_input ( "Enter name: " ) print ( name ) To test your version: python –version String Comparison To test if two strings are equal use the equality operator (==). #!/usr/bin/python   sentence = "The cat is brown" q = "cat"   if q == sentence: print ( 'strings equal' ) To test if two strings are not equal use the inequality operator (!=) #!/usr/bin/python   sentence = "The cat is brown" q = "cat"   if q != sentence: print ( 'str...

If else statements

In Python you can define conditional statements, known as if-statements. A block of code is executed if certain conditions are met. If statements Consider this application, it executes either the first or second code depending on the value of x.   #!/usr/bin/python   x = 3 if x < 10 : print ( "x smaller than 10" ) else : print ( "x is bigger than 10 or equal" ) If you set x to be larger than 10, it will execute the second code block.   We use indentation (4 spaces) to define the blocks. A little game: A variable may not always be defined by the user, consider this little game: age = 24   print "Guess my age, you have 1 chances!" guess = int ( raw_input ( "Guess: " ) )   if guess != age: print ( "Wrong!" ) else : print ( "Correct" ) Conditional operators A word on conditional operators Operator Description != not equal == equals > greater than < smaller than ...