Python study_note

这篇博客介绍了Python的基础知识,包括字符串操作、赋值语句、输入输出、条件判断、循环语句和自定义函数。通过实例展示了如何使用这些概念,并强调了Python代码的简洁性。还提及了eval()函数的危险性,提醒读者谨慎使用。
摘要由CSDN通过智能技术生成

@author bingxian (Ongoing update …)

Day 1

INTRODUCTION

(copy by my IDE, so everything display in code’s way)

this is my Python study place and my study note

there will include major grammar of Python

the code will all be turn into annotation, you can recover the part of code you want to execute

the word in ‘[]’ is ths thoughts of me – bing_xian

# this is an annotation
'''
this is also an annotation
'''
'''
String 

string is an sequence of char 
the most important characteristic the String has in Python is it can search char in a inverted order

something like 
```python

word = "hello world"
print(word[-1])

```
this code will end up with output : 'd'

```python

word = "1000c"
print(word[0:-1])

```
this code will end up with output : '1000'

'''

# print(" -- following is the test place of string -- \n")
#
# print("1.test of inverted order")
# word = "hello world"
# print("the last char of 'hello world' is : " + word[-1] + "\n")
#
# print("2.test of substring")
# num = "1000c"
# print("the '1000c''s substring from index '0' to index '-1' is : " + num[0:-1] + '\n')
#
# print("-- test of string has completed --")

'''
assignment

python's assignment is also special that it have following grammar

<variable_1>, <variable_2>, <variable_3>, ... = <expression_1>, <expression_2>, <expression_3>, ...

```python

x = 1
y = 2
x, y = y, x

```

this is the simple version of

```python

x = 1
y = 2
t = x
x = y
y = t

```

the emergence of this grammar will immensely simplify the code of Python
[too elegant]

'''

# print(" -- following is the test of annotation -- \n")
#
# x = 1
# y = 2
# x, y = y, x
#
# print("x = 1\ny = 2\n and when finishing execute x, y = y, x, we would find that : \nx = " + str(x) + "\ny = " +
# str(y) + "\n")
#
# print(" -- test of annotation has completed -- ")

'''
input() method

we can obtain the input from console by method : input()
this method will return a string, whatever input is

```python

tempStr = input("please input something ... : ")
print(tempStr)

```
result will be the input from console

'''

# tempStr = input("please input something ... : ")
# print("result is : "tempStr)

'''
branch statement

Python combine 'else' and 'if' into 'elif' if they been used constantly

```python

if <condition_1>:
    <code_1>
elif <condition_2>:
    <code_2>
...
else:
    <code_N>

```
then the <code_1>, <code_2>, ..., <code_N> will be executed in given order

'''

# tempStr = '123'
# if tempStr[-1] in ['2', '1']:
#     print("the last char of '123' is in the list ['2', '1']")
# elif tempStr[-1] in ['3']:
#     print("the last char of '123' is in the list ['3']")
# else:
#     print('something is going wrong')

'''
eval() method

this method is a great creation that it can turn string into code and execute!!!!!!!!
then it will output the result of this string expression

```python

x = 1
eval("x + 1")
eval("1.1 + 2.2")

```
result and 2 and 3.3

'''

# x = 1
# eval("x + 1")
# eval("1.1 + 2.2")

'''
print() method

print out the variable inside '()'
[so simple that its example is needless]

'''

# print("this is print() method")

'''
loop statement

grammar is :

while <condition>:
    <code>

the <code> will be executed again and again till <condition> turns into 'false'

```python

condition = 1
while condition < 10:
    print("condition = " + str(condition++))
    condition = condition + 1

```
the variable 'condition' will keep adding up with 1 till it bigger than 10 

'''

# condition = 1
# while condition < 10:
#     print("condition = " + str(condition))
#     condition = condition + 1

'''
keyword 'def'

'def' can make you define your own custom method

```python

def printOutNum():
    print("i don't want to obey your order. hum!")

printOutNum()

```
[this method is tsundere ]

'''


# def printOutNum():
#     print("i don't want to obey your order. hum!")
#
#
# printOutNum()

程序截图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值