Python Identifiers:
A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).Python does not allow punctuation characters such as @, $ and % within identifiers. Python is a case sensitive programming language. Thus, Manpower and manpower are two different identifiers in Python.
Here are following identifier naming convention for Python:
- Class names start with an uppercase letter and all other identifiers with a lowercase letter.
- Starting an identifier with a single leading underscore indicates by convention that the identifier is meant to be private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Multi-Line Statements:
Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character (\) to denote that the line should continue. For example:total = item_one + \ item_two + \ item_threeStatements contained within the [], {} or () brackets do not need to use the line continuation character. For example:
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
Waiting for the User:
The following line of the program displays the prompt, Press the enter key to exit and waits for the user to press the Enter key:#!/usr/bin/python raw_input("\n\nPress the enter key to exit.")Here, "\n\n" are being used to create two new lines before displaying the actual line. Once the user presses the key, the program ends. This is a nice trick to keep a console window open until the user is done with an application.
Multiple Statements on a Single Line:
The semicolon ( ; ) allows multiple statements on the single line given that neither statement starts a new code block. Here is a sample snip using the semicolon:import sys; x = 'foo'; sys.stdout.write(x + '\n')
disarikan dari http://www.tutorialspoint.com/python/python_basic_syntax.htm
0 komentar:
Posting Komentar
tinggalkan komentar Anda