Showing posts with label TIA academy. Show all posts
Showing posts with label TIA academy. Show all posts

Friday, 10 February 2017

Range Functions and Sequences in Python


Range() generates lists containing arithmetic progression.
Three variations of range() function
>> range(stop) – Starts from 0 till (stop – 1)
>> range(start,stop) – Ends at (stop – 1)
>> range(start,stop,step) – Step cannot be 0, default is 1
Example of Range Function
range(stop) - If the range is defined as 5, it would simply show the list of numbers falling in the range from 0 to 5. The default range starts from 0 and stops before 5, as defined.
range(start, stop) – The point of starting as well as stopping is defined in this. As shown in the example below, the start range has been defined as 5, while stop range as 10. Hence, it would display the numbers 5, 6, 7, 8, 9, which range between 5 to 10.
range(start, stop, step) - The first two values defined here are the same, start and stop, while the third one is step, which means the difference between every two consecutive numbers. For example, if range is defined in this way: range(0, 10, 2). It will give away numbers between 0 to 10, but with a difference of 2, in this way: [0, 2, 4, 6, 8]. The step here cannot be given 0 value. It has to be 1 or greater than 1.
Sequences in Python
A sequence is the succession of values bound together by a container that reflects their type. Almost every stream that we put in Python is a sequence.
Types of Sequences
  • Lists
  • Tuples
  • Xrange
  • String
The python is supported by some other sequences are strings, lists, tuples and Xrange objects. Python has a bevy of methods and formatting operations that can perform.
List
  • A list is a sort of container which holds the number of other objects, in a given order.
  • The list type implements the sequence protocol which allows adding and removing objects from the sequence.
  • It is an ordered set of elements enclosed in square brackets.
Simple definition of list – li = []
li = list() # empty list
li = list(sequence)
li = list(expression for variable in sequence)
example
            >>> list(a)
            [‘e’, ‘x’, ‘a’, ‘m’, ‘p’, ‘l’, ‘e’]
            >>> list3 = [‘Hadoop’, ‘Python’, ‘Data Science’, ‘Pig’, ‘hive’]
            >>> list3
            [‘Hadoop’, ‘Python’, ‘Data Science’, ‘Pig’, ‘hive’]
            >>> list3[2:]
            [‘Data Science’, ‘Pig’, ‘hive’]
            >>> list3[2:3]
            [‘Data Science’]
            >>> list3[2:4]
            [‘Data Science’, ‘Pig’]
            >>> list3[2:5]
            [‘Data Science’, ‘Pig’, ‘hive’]
            >>>
Accessing List Elements
To access the elements of a list:
n = len(li)
item = li[index] #Indexing
slice = li[start:stop] #Slicing
List Indexing

list[i] returns the value at index i, where i is an integer. A negative index accesses elements from the end of the list counting backwards. The last element of any non-empty list is always li[-1]. Python raises an IndexError exception, if the index is outside the list.

Accessing Command Line Arguments

Python supports the creation of programs that would run on the command line, completely with command-line arguments. It provides getopt modules that parse the command line options and arguments. The Python sys module provides access to any of the command-line arguments via sys.argv. It solves two purposes:
  • sys.argv is the list of command line arguments
  • len(sys.argv) is the number of command line arguments that are in the command line
  • sys.argv[0] is the program, i.e. script name

Executing Python

The python should be executed in the following
$python Commands.py inp1, inp2 inp3

Example

import sys
print ‘Number of arguments:’, len (sys.argv), ‘arguments.’
print ‘Argument List:’, str(sys.argv)
It will produce the following output:
Number of arguments: 4 arguments.
Argument List: [‘sample.py’, ‘inp1’, ‘inp2’, ‘inp3’]
If you have any queries? Mention them in the comments section and we will clarify you.

Wednesday, 25 January 2017

Python For Beginners

Python For Beginners

Welcome! Are you completely new to programming? If not then we presume you will be looking for information about why and how to get started with Python. Fortunately an experienced programmer in any programming language would pick up Python very quickly. It's easy for beginners to use and learn, so jump in!
Installing
Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. Even some Windows computers come with Python already installed. If you need to install Python and aren't confident about the task you can find a few notes but installation is unremarkable on most platforms.
Learning
Before getting started, you may want to find out which IDEs and text editors are tailored to make Python editing easy, browse the list of introductory books, or look at code samples that might helpful.
There is a list of tutorials suitable for experienced programmers. There is also a list of resources in other languages which might be useful.
The online documentation is the first port of call for definitive information. There is a fairly brief tutorial that gives the basic information about the language and gets started. Follow this by looking at the library reference for a full description of Python libraries and the language reference for a complete explanation of Python's syntax. If you are looking for common Python recipes and patterns, browse the Active State Python Cookbook.
Looking for Something Specific?
If you want to know whether a particular application, or a library with particular functionality, is available in Python there are a number of possible sources of information. The Python web site provides a Python Package Index (also known as the Cheese Shop, a reference to the Monty Python script of that name). There is also a search page for a number of sources of Python-related information. Failing that, just Google for a phrase including the word ''python'' and get the result. If all fails, ask on the python newsgroup is a good chance someone will put you on the right track.


Thursday, 12 January 2017

Future Scope of Python


Future Scope of Python

Python would be a critical piece of Google. Today, many Google engineers utilize Python, and we're searching for more individuals with abilities in this language.  "Python is staying put! What's more, we have motivations to express that”.

Python programming would expand fame among the masses and Linux people group is additionally being utilized by enormous players like Google. Python is a far reaching and real abnormal state programming dialect which is generally connected with Linux area of clients. It is an open source dialect loaning backing to the fundamental programming codes that are in the vogue.

The best part is that python software engineers can compose codes that can be protest arranged, utilitarian or basic in plan. This dialect was composed to give stage autonomy and code lucidness as a main priority. These 2 remarkable elements make this dialect legitimate and versatile and additionally less demanding to get it. The adaptability in which the Python runs same source code on a wide cluster of stages. Python has been depicted as most sorted out and institutionalized dialect by a few clients. With these momentous forces, and versatility over numerous stages, this dialect guarantees a well manufactured vocation ahead for every one of the wannabes.

How the Python having a long way to go

In a late overview directed in online by Linux Journal, Python has been voted as a standout and most loved programming dialect beating any semblance of C, C++ and JAVA. Python world are open source and have a lot of cooperative energy between them.

Python is utilized among worldwide in an extensive variety of environment. Be it as a piece of aptitudes, for corporate, it is being educated at both passage and in addition propelled level. It doesn't end here; utilized by Google machine and enormous ventures like Red Hat, Disney and so forth.

It's adaptable, hearty and thorough programming dialect being highlighted in the 10 most prominent programming dialects utilized as a part of the business.

It has genuine compactness highlights and can be utilized over a large number of stages; its adaptability and extensibility make it cherished by developers.

Comprehension of Python shows comprehension of Linux frameworks. Both the stages are packaged together and Python goes as a standard component for engineers and Linux directors. It is effectively utilized as a part of a large number of business applications.

It is a free and open source being favored over different choices. To rehearse and learn, select some expert in Python programming. It comprehends the ideas and execution. Doubtlessly, Python is not going to blur away until further notice!