Friday, July 16, 2021

python class

 Expression

tools: subline pycharm


2 = 2 -> expression, evaluate to a single value.

>>> 2 -> expression 2 evaluates it self.

>>> 2 * 2
>>


>>> 2 + 2
4
>>> 5-3
2
>>> 3 * 7
21
>>> 3 x 7
SyntaxError: invalid syntax
>>> 22 / 7
3.142857142857143
>>> 2 + 3 * 6
20
>>> (2+3) * 6
30
>>> (2 + 3) * 6
30
>>> (5 - 1) * ((7+1) / (3 - 1))
16.0
>>> 5 +
SyntaxError: invalid syntax
>>>


Data type

ints, floats, Strings
40, 42.5, hello

>>> 40
40
>>> 40.1
40.1
>>> "Hello, World"
'Hello, World'
>>> 'Hello' + 'Hello'
'HelloHello'


>>> "Hello, World"
'Hello, World'
>>> 'Hello' + 'Hello'
'HelloHello'
>>> 'Hello' + '!'
'Hello!'
>>> 'Hello' + '!' * 10
'Hello!!!!!!!!!!'
>>> 'Hello' * 2
'HelloHello'
>>> 'Hello ' * 10
'Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello '
>>>



Assignment Statement
a=10


You can use variable in expression anywhere you normally use. Variable evaluates value it contains.
>>> a=5
>>> b=10
>>> apple=4
>>> apple
4
>>> a + b
15
>>>

Every variable stores one data type.

>>> a+b
'helloworld'
>>> a + b
'helloworld'
>>> a + 'world'
'helloworld'
>>> a + ' World'
'hello World'
>>> a + 1
Traceback (most recent call last):
  File "<pyshell#36>", line 1, in <module>
    a + 1
TypeError: can only concatenate str (not "int") to str
>>> a = 2
>>> a + 1
3
>>>


Review
- IDLE is an python editor program
- Interactive shell (>>>) and file editor
- Expressions = Value + Operators
- int, float, string
- 'Hello, World'
- a = 2
= a + 1


IDLE is an interactive shell. You can  you file eidtor to write complete program. Click on File -> New FIle on IDLE to open a text editor.


===============================

Writing first program
- Open IDLE
- Click on File -> New file


# THis program prints hello and ask your name

print('Hello, World !!!')
print('Please eneter your name?') # asking for name
myname = input()
print('It is a good to meet you,




No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...