Skip to main content

Python - Learning - Important point.

Abstract from https://docs.python.org/3/tutorial/introduction.html
Numbers
Comments in Python start with the hash character, #, and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. 

The interpreter acts as a simple calculator: you can type an expression at it and it will write the value. Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses (()) can be used for grouping.


The integer numbers (e.g. 2, 4, 20) have type int, the ones with a fractional part (e.g. 5.0, 1.6) have type float. We will see more about numeric types later in the tutorial.

Division (/) always returns a float. To do floor division and get an integer result (discarding any fractional result) you can use the // operator; to calculate the remainder you can use %

With Python, it is possible to use the ** operator to calculate powers 

Strings
Strings can be enclosed in single quotes ('...') or double quotes ("...") with the same result [2]. \ can be used to escape quotes

If you don’t want characters prefaced by \ to be interpreted as special characters, you can use raw strings by adding an r before the first quote.
print(r'C:\some\name')

String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line.

Strings can be concatenated (glued together) with the + operator, and repeated with *.

Two or more string literals (i.e. the ones enclosed between quotes) next to each other are automatically concatenated.

Strings can be indexed (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one.Indices may also be negative numbers, to start counting from the right.Note that since -0 is the same as 0, negative indices start from -1.
In addition to indexing, slicing is also supported. While indexing is used to obtain individual characters, slicing allows you to obtain substring

Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced.

Attempting to use an index that is too large will result in an error.
The built-in function len() returns the length of a string.


Lists
Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type
Like strings (and all other built-in sequence type), lists can be indexed and sliced.
Lists also support operations like concatenation.
Unlike strings, which are immutable, lists are a mutable type, i.e. it is possible to change their conten.You can also add new items at the end of the list, by using the append() method (we will see more about methods later).
Assignment to slices is also possible, and this can even change the size of the list or clear it entirely,

Conditionals 
The built-in function len() also applies to list.It is possible to nest lists (create lists containing other lists).

Multi Assignments
a, b = 0, 1
a, b = b, a+b

In Python, like in C, any non-zero integer value is true; zero is false. The condition may also be a string or list value, in fact any sequence; anything with a non-zero length is true, empty sequences are false. 
The standard comparison operators are written the same as in C: < (less than), > (greater than), == (equal to), <= (less than or equal to), >= (greater than or equal to) and != (not equal to).
The body of the loop is indented: indentation is Python’s way of grouping statements. At the interactive prompt, you have to type a tab or space(s) for each indented line.
The print() function writes the value of the argument(s) it is given. It differs from just writing the expression you want to write (as we did earlier in the calculator examples) in the way it handles multiple arguments, floating point quantities, and strings. Strings are printed without quotes, and a space is inserted between items, so you can format things nicely,The keyword argument end can be used to avoid the newline after the output, or end the output with a different string.





Comments

Popular posts from this blog

Installing OpenERP on Ubuntu 12.04

1. Install Ubuntu Server with OpenSSH Server.So that you can run your commands from a remote server. 2. Run the following commands to install required depedency sudo apt-get install postgresql postgresql-client python-dateutil python-feedparser python-gdata python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi 3. Download Latest Openerp all file wget http://nightly.openerp.com/6.1/releases/openerp_6.1-1-1_all.deb 4. Install openErp server. sudo dpkg -i openerp_6.1-1-1_all.deb sudo apt-get install openerp -f 5. Reboot 6. Access the Web Client using http://ip:8069

20 Extensions for VSCode For Node+Angular2 Development

Here is the list of Extensions which I found important and Interesting. The names are in the form of  Author.Name christian-kohler.npm-intellisense CoenraadS.bracket-pair-colorizer DavidAnson.vscode-markdownlint dbaeumer.jshint donjayamanne.githistory ecmel.vscode-html-css eg2.tslint eg2.vscode-npm-script fknop.vscode-npm formulahendry.auto-close-tag formulahendry.auto-rename-tag HookyQR.beautify humao.rest-client lonefy.vscode-JS-CSS-HTML-formatter mkaufman.HTMLHint msjsdiag.debugger-for-chrome prashaantt.node-tdd rbbit.typescript-hero robertohuertasm.vscode-icons Zignd.html-css-class-completion See the following link to quickly install these extensions. Here is the extension.json . https://code.visualstudio.com/docs/editor/extension-gallery#_workspace-recommended-extensions

OpenERP 7 on Ubuntu

install the following sudo apt-get install graphviz ghostscript postgresql-client python-dateutil python-feedparser python-matplotlib python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-imaging gcc python-dev mc bzr python-setuptools python-babel python-feedparser python-reportlab-accel python-zsi python-openssl python-egenix-mxdatetime python-jinja2 python-unittest2 python-mock python-docutils lptools make python-psutil python-paramiko poppler-utils python-pdftools antiword postgresql sudo -u postgres createuser -s openerp install using To install the Debian/Ubuntu package, add the following line to your /etc/apt/sources.list: deb http://nightly.odoo.com/7.0/nightly/deb/ ./ And type: sudo apt-get update sudo apt-get install openerp