codecamp

基础操作

我们开始学习Python吧。


输出 先举一个新手也得会的操作:

print("Hello World!")

运行后查看输出,就会发现出现了: Hello World! 来解释一下代码:print()函数是用来输出内容的;这里再举几个例子:

print(1234567)
print("hi")
print('BHNB')

这里再解释一下输出字符串的时候字符串两边需要加上"或者',不过千万不能混用!不然就这样了:

print('hi")  #这个是代码
  File "<python-input-0>", line 1
    print('hi")
          ^
SyntaxError: unterminated string literal (detected at line 1)

输入 当然,有输出就得有输入。

input("你叫什么")

input()函数是检测输入的,不过要是想用它干点儿什么,就得使用变量了,我们下一节再讲。

Python配置
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }