001学习python

本文详细介绍Python的安装步骤及基本操作,包括内置函数的使用、简单的交互式程序编写等,适合Python初学者快速入门。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载安装python地址在https://www.python.org/download,选择合适的版本,

2.安装python,全部next。

3.打开IDLE,测试print输出如下:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
//标准输入格式,语句结束分号可有可无
>>> print("I LOVE dcd")
I LOVE dcd
>>> print('123') //单引号yekeyi
123
>>> PRINT(" LOVE");//不支持大写
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    PRINT(" LOVE");
NameError: name 'PRINT' is not defined
>>> print " 123"//错误语法
SyntaxError: invalid syntax

>>> printf("123")//c语言语法不支持
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    printf("123")
NameError: name 'printf' is not defined

>>> print(5+3)   //可以直接计算
8

>>> print(5+s)  //错误
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    print(5+s)
NameError: name 's' is not defined

>>> 123456*654321   //可直接进行计算
80779853376


>>> print("well water " + "river")   //字符串粘贴
well water river

>>> print("你好"*8)    //有无换行符区别  字符串直接*8,输出结果也是直接输出8个
你好你好你好你好你好你好你好你好
>>> print("你好\n"*8)
你好
你好
你好
你好
你好
你好
你好
你好

//字符串后+8提示
>>> print("你好\n"+8)
Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    print("你好\n"+8)
TypeError: Can't convert 'int' object to str implicitly
>>> 

4.编写一个小程序。python中的程序块是用缩进来表示,相当于c中的括号,缩进使用错误,会带来程序结果的错误

print("------------我爱dcd-----------")
tem = input("不妨猜一下我现在心里想的那个数字:")    //py里面变量是不分类型的,int()是转化成整型
guss = int(tem)
if guss == 8:
    print("你是蛆吗?")
    print("好吧,你是")
else:
    print("你猜错啦,我心里想的是8")
print("游戏结束,不玩啦")

if和else后面都跟有冒号。

5.内置函数,如print,input,在shell中输入dir(__builtins__)   前后两个下划线下面图中,全小写的就是内置函数


查询py中内置函数的功能,使用help(**)


6.编写一个程序,输入名字,然后打印出来

print("------------我爱dcd-----------")
tem = input("你的名字:")
print(tem)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值