输出与输入-量子电子学
3.1输出与输入一般编程语言的教程都从打印“Hello World!”开始,我们这里也不免俗套,从打印开始。 3.1.1 print打印Python提供print方法来打印信息,下面打开Python shell来打印一些信息。 Python shell ActivePython 2.7.6.9 (ActiveState Software Inc.) based on Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print "hello" hello调用print方法,用户双引号(" ")把需要打印输出的信息引起来就被输出了。可是,我给你什么信息,你就打印什么,这个很无聊!那我们就打印点有意思的。让打印信息向你问好。 Python shell >>> name = "zhangsan" >>> print "hello %s ,Nice to meet you!" %name hello zhangsan ,Nice to meet you! >>> name = "Lisi" >>> print "hello %s ,Nice to meet you!" %name hello Lisi ,Nice to meet you!虽然,我们两次的打印语句一样,但由于定义的变量name两次赋值不同,那么打印出的结果也不完全相同。%s(string)只能打印字符串,如果想打印数字,那么就要使用%d(data)。 Python shell >>> age=27 >>> print "You are %d !" %age
8.1MB
文件大小:
评论区