What does the sign mean in Python
Brief overview of programming with Python |
Data types
Integer | i = 1 | Integer |
Float | f = 0.1 | Floating point number |
String | s = "Hello" | String |
list | l = [1, 2, 3] | Changeable list with order |
Tuple | t = (1, 2, 3) | Unchangeable list with sequence |
Dictionary | d = {1: "one", 2: "two", 3: "three"} | Associative array |
Conversion of data types
int (2.33) returns 2
float (3) returns 3.0
str (53) returns the number 53 as a string
Expressions and operators, meaning in brackets
arithmetic
+ (plus), -(minus), * (times), / (divided by), ** (high), % (Modulo, remainder of a division)
16/3 returns 5 (integer division), 16.0 / 3 returns 5.333333333333333 (floating point number division)
Comparisons
==(equal), != (not equal),> (larger), <(smaller),> = (larger or equal), <= (smaller or equal)
logic
true (true), false (not correct), other (simultaneously), or (or), not (Not)
Element relationship
in (in the crowd), e.g. 3 in [1, 2, 3] (true), 4 not in [1, 2, 3] (true)
Strings
Strings can be used with + linked or with * be repeated, e.g.
"ABC"+“Def“ returns “abcdef“, 5*"A" delivers "AAAAA"
Sequences
Sequences are called tuples (1, 2, 3) and lists [1, 2, 3]. In contrast to dictionaries, sequences are ordered, i.e. each element has a unique position, starting with position 0 (Zero) for the first element of the list, -1 can be set for the last element, e.g. (3, 4, 5) [0] returns 3, (3, 4, 5) [- 1] returns 5
List Generators
range (10) equivalent to [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], range (1.4) corresponds to [1,2,3]Function definition
def square (x): return x ** 2square (3) returns 9Commands for numbers and strings
round (a [, n]) - rounds a floating point number. Optionally, the number of decimal places can be specified, e.g.
round (5.59555, 2) returns 5.6
str () - convert to string, float () - convert to floating point number.
You can use not only numbers, but generally all objects str () convert to a string, e.g.
print(str(167) [- 1]) yields 7
len() - Determine the length of the string, e.g.
test_string = "Today"
len(test_string) returns 5
Control structures
if-elif-else Example:
x = 8 if x> 5: print ("x is greater than 5") elif x <5: print ("x is less than 5") else: print ("x is 5" Output: x is greater than 5while Example: i = 0 while i <4: print ("i is", i) i = i + 1 Output: i is 0 i is 1 i is 2 i is 3 for Example:for i in range (10.21): print(i * i, end = '' 100 121 144 169 196 225 256 289 324 361 400 break,Example:continue and else for i in "Hello World!":if i == "":break print (i, end = '') Output: HelloModules
from ... import ... e.g. from math import * Importance: Everything (*) is imported from the math module.Input and output
a = input (“Text“) #Entering the variable aprint “Text“, a # Output of text and value of the variable aExample:
i = 99
print ('% 3d% 1.6f'% (i, 1.0 / i)
Output:
99 0.010101keywords
and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield
Program input
The program input is best done in a new Windows window (Ctrl + N) after calling IDLE (Python GUI).
Back
Back to the home page
- How to say idol in Indonesian
- Can a transgender woman be a model
- How is the electrical and electronic equipment at JNTU Kakinada
- Which GoPro or DSLR cameras are better
- Is the night healthy
- What should we know about Fox News
- Is what I learn useful
- Why is it ineffective to study Japanese abroad?
- What is the best advice to be successful
- Why did Jesus resist circumcision?
- Why can I see but not remember
- Which songs do you know in Turkish?
- Fish farming is dangerous
- Which platonic body has 12 sides?
- Which trends shape modern economies
- How can I help Palestinian children
- We recommend LinkedIn and Facebook connections
- What is the proof of tax compliance
- What is your opinion on my answers
- In what situations does silence mean consent?
- What is erythroid hyperplasia
- What is the best anti-anxiety drug
- Hormonal imbalance can reduce the size of women
- Which muscles are responsible for breathing?