Sunday, 1 October 2017

BASIC PYTHON LEARNING- PHASE 1

Before going towards learning of Python language, It become important to know the Applications of Python. And, I try to cover most of the applications in below figure😃.




Now, let start with learning toward python language:

VARIABLE AND DATA TYPES
  • Variables are used to store values in reserved memory locations, means memory can be saved when variables are created.
  • It can be local or Global.
  • Local variables are declared inside the body of function and it can be limited to this function only, can’t access outside.
  • Global variable declare outside and can be accessed from anywhere.
The Data types used to stores value in Variables in Python are of different types as shown in below Figure:


Let’s discuss all data type in details with Programs:

1.       Numbers:
      These data type store numeric values which are immutable. It means if we change the value of data type number, then it will store as new object in memory.
There are 4 types of numbers: signed  integer, long integers, floating point integer, complex numbers.
In spite of above, there are some mathematical functions also.
1.       Random functions
2.       Trigonometric functions
3.       Mathematical Functions
2.       Strings:
Characters in single or double quotes
No character in Python, String of length one is Character only.
Strings are also immutable.
There are different operators used in Strings. Some common operators are concatenation (+), replication (*), in, not in operators, relational or comparison.
3.       Lists:
Different type of the data can be hold at a time.
List can be represented with elements and these elements can be accessed and retreived using index.
Index can be 0 to n.
All elements are separated with comma and enclosed with closed bracket. This represent the list.
Elements can be added and deleted from the list. It means new list will not create every time when we changed elements and its values. Thus, mutable.
+ and * operators can also be used in lists.
There are some common functions and method used for Lists are max, min, len, cmp, index, count, insert, remove, sort, reverse, pop, extend.
4.       Tuples:
The first 3 points are same as list.
But tuple enclosed in parenthesis ().
Tuple are immutable, can’t change the value of elements. Data safe in tuple due to this.
+ and * operators are also used in tuple.
Delete operation can be performed in tuple.
There are some common functions and method used for Lists are max, min, len, cmp, index, count, insert, remove, sort, reverse, pop, extend.
Fast Processing  in tuple.
5.       Dictionary:
Key value pair separated with colon(:)
Dictionary enclosed in curly braces {}
Keys are unique, but not values in dictionary
Updating and Deletion are possible using keys. Means dictionary are immutable.

OPERATORS IN PYTHON




FUNCTIONS IN PYTHON
  • Function - Reusable code -  written once and whenever required use it in Program.
  • We call Function as subprogram, part of program
  • Eg: some built in function like print(), close()
  • Def: used to start the function followed by function name and then parenthesis
  • Parameters can be passed in these parenenthsis  which acts as argument or parameter
  • But parameters must be variable, while argument can be variable, literal, expression.
  • Function must return to send back the control to the function and exit from it.

def employee(id, name):
{
Print id
Print name
return
}
employee(id=1, name=’isha’)
employee(id=2)

Arguments in Function
  • Positional Argument: Order and number of argument must match with argument passing in Function. Like for subtraction of two elements, both value should be present. If one is missing, function will not return anything while calling.
  • Default Argument: provide default value to the argument, eg: name=’akansha’ in above program.  def employee(id, name=’Akansha’)
  • Keyword Argument: During calling of function, argument must matched with function on basis of parameter name.
                employee( name=’neha’, id=6)

PYTHON INPUT & OUTPUT

Input and Output are used for reading and writing. There are two built in function used in Python which takes input from Keyword or which user wish to give.
  1. input()- Any expression is given as input by user.
  2. raw_input()- input is always in the form of string. Thus, this function always returns String. But, typecasting can be used to convert it into some another form.
Handling of Files:
  • A file can be used to store and retrieve data.  Firstly the file should be open before reading and writing in file using the method open(filename, mode, buffer). Once Operation on the file is done, file should be close using the method close().
  • Read() method is generally used to read data from file and write() method to write string into file.
  • There are some other methods also in File handling: mkdir, chdir, rmdir, rename, remove, getcwd, tell.
If anyone wants to see the real time implementation of the above Python tutorial, You can visit my link:

https://drive.google.com/drive/folders/0Bz02Fv4ao4_4NWpIVERqOG5zQ00


At the last, I sincerely thanks the sources JavaTpoint, TutorialPoint, Python.org which help me to learn the basics of Python and also Python 3.5 IDLE which help me to gain practical experience by Coding.
1. https://www.javatpoint.com/python-tutorial
2. https://www.tutorialspoint.com/python/
3. https://docs.python.org/3.3/library/functions.html


Thanks all for reading this blog !!










No comments:

Post a Comment