Python, like all programming languages has conventions that we must follow.
Some programming languages use punctuation such as braces ({}) and semicolons (;) to structure code blocks. Python is somewhat different (and easier on the eye) because it uses white space and indentation to define code structure. 3 Sometimes code needs a little explanation, so we use comments to help readers of the code (including you) understand it. We introduce indentation and comments with some examples.
# some text after hashes
# brdr = 2 # thick border
Any text that appears after a hash character (#) is ignored by the interpreter and treated as a comment. We use comments to provide documentation.
Variables :
A variable is a named location in the program’s memory that can be used to store some data. There are some rules for naming variables:-
• The first character must be a letter or underscore ( _ ).
• Additional characters may be alphanumeric or underscore.
• Names are case-sensitive.
" var = expression "
An expression could be a literal, a calculation, a call to a function, or a combination of all three. Some expressions generate a list of values; for example:
Here are some more examples:
>>> # 3 into integer myint
>>> myint = 3
>>>
>>> # a string of characters into a string variable
>>> text = 'Some text'
Some programming languages use punctuation such as braces ({}) and semicolons (;) to structure code blocks. Python is somewhat different (and easier on the eye) because it uses white space and indentation to define code structure. 3 Sometimes code needs a little explanation, so we use comments to help readers of the code (including you) understand it. We introduce indentation and comments with some examples.
# some text after hashes
# brdr = 2 # thick border
Any text that appears after a hash character (#) is ignored by the interpreter and treated as a comment. We use comments to provide documentation.
Variables :
A variable is a named location in the program’s memory that can be used to store some data. There are some rules for naming variables:-
• The first character must be a letter or underscore ( _ ).
• Additional characters may be alphanumeric or underscore.
• Names are case-sensitive.
Common Assignment Operations
When you store data in a variable it is called assignment. An assignment statement places a value or the result of an expression into variable(s). The general format of an assignment is:" var = expression "
An expression could be a literal, a calculation, a call to a function, or a combination of all three. Some expressions generate a list of values; for example:
Here are some more examples:
>>> # 3 into integer myint
>>> myint = 3
>>>
>>> # a string of characters into a string variable
>>> text = 'Some text'
Thanks for reading................
No comments:
Post a Comment