0% found this document useful (0 votes)
39 views

Could Also Use A Value

The document discusses Python syntax and concepts including: - Operator precedence follows PEMDAS with ** evaluated first, then *, /, //, %, followed by + and - from left to right. Parentheses can override precedence. - Variables must follow naming rules: one word, letters, numbers, underscore, no starting number. Variables are case sensitive. - Comments are lines prefixed with #. Print statements display output, input() returns a string, and len() returns an object's length. Functions evaluate arguments and return values.

Uploaded by

Monis Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Could Also Use A Value

The document discusses Python syntax and concepts including: - Operator precedence follows PEMDAS with ** evaluated first, then *, /, //, %, followed by + and - from left to right. Parentheses can override precedence. - Variables must follow naming rules: one word, letters, numbers, underscore, no starting number. Variables are case sensitive. - Comments are lines prefixed with #. Print statements display output, input() returns a string, and len() returns an object's length. Functions evaluate arguments and return values.

Uploaded by

Monis Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

The ** operator is evaluated first; the *, /, //, and % operators are evaluated next, from left to right; and

the + and - operators are evaluated last (also from left to right). You can use parentheses to override the
usual precedence if you need to.---[PYTHON follows PEMDAS i.e. Parenthesis, Exponents, Multiplication,
Division, Addition, Subtraction; PEMD(IqR)AS]

Python executes code from left to right & from top to bottom

If you ever see the error message SyntaxError: EOL while scanning string literal, you probably forgot the
final single quote character at the end of the string

Expressions consist of values (such as 2) and operators (such as +), and they can always evaluate (that is,
reduce) down to a single value. That means you can use expressions anywhere in Python code that you
could also use a value.

An assignment statement consists of a variable name, an equal sign (called the assignment operator),
and the value to be stored.

A variable is initialized (or created) the first time a value is stored in it. When a variable is assigned a new
value, the old value is forgotten. This is called overwriting the variable. Variable names are case-
sensitive. It is a Python convention to start your variables with a lowercase letter [Same is the case with
commands].

You can name a variable anything as long as it obeys the following three rules:

1. It can be only one word.


2. It can use only letters, numbers, and the underscore (_) character.
3. It can’t begin with a number
Sometimes, programmers will put a # in front of a line of code to temporarily remove it while testing a
program. This is called commenting out code, and it can be useful when you’re trying to figure out why a
program doesn’t work.

The line print('Hello world!') means “Print out the text in the string 'Hello world!'.” When Python
executes this line, you say that Python is calling the print() function and the string value is being passed
to the function. A value that is passed to a function call is an argument.

An expression evaluates to a value. A statement does something. Statements represent an action or


command e.g print statements, assignment statements.

(1)The input() function always returns a string, even if the user enters a number. (2) The int() function is
also useful if you need to round a floating-point number down for ex, int(9.99)=9. (3) You can also use
this function to put a blank line on the screen; just call print() with nothing in between the parentheses .
(4) Round function in python rounds up value only on the basis of mod value of a number and not it’s
sign i.e. round(99.99) is equal to 100 and round(-99.99) is equal to -100.[Detail:
https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues ] (5)The function len() returns the
length (the number of items) of an object. The argument may be a sequence (such as a string, bytes,
tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

Following is the manner in which python executes a function

You might also like