最近在学习Python,为了督促自己,特此在CSDN上记录学习过程。本人初级程序员,觉得Python入门简单一些,平时业余时间学习一下,由浅入深,希望看到的人不要笑我。
谢谢大家,希望大家也来监督我哟。
Python 版本 3.5.1
最先说的还是 input( ) 了。
Python 2.7的 raw_input( ) 已经 替换成了 input( )
-
Converts
raw_input()
toinput()
.
raw_input
-
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read,
EOFError
is raised. Example:>>> s = input('--> ') --> Monty Python's Flying Circus >>> s "Monty Python's Flying Circus"
If the
readline
module was loaded, theninput()
will use it to provide elaborate line editing and history features.
input
(
[
prompt
]
)
本来还有些纠结,看来不能用raw_iput( ) 了。
简单练习1.
输入一个数字,并打印出来
#!/usr/bin/env python
a = input()
b = input()
a = int(a)
b = int(b)
print("a = %d"%a)
c = a % b
d = a ** b
print("c = %d"%c)
print(a)
输出结果:
4
5
a = 4
c = 4
4
简单练习2.
输入一个字符串,用for 打印出单个字符。
a = input("input a string")
for i in a:
print(i)
输出结果:
input a stringpython
p
y
t
h
o
n