Python自学笔记(一)

@Python自学Python3第一天

关键词:输入输出 变量命名 赋值 数据类型 运算 函数 包 模块

Python输入输出

【输出】print函数

python使用print函数输出

  1. print(变量)
  2. print(字符串)

【输入】input函数

  1. input() 返回类型是 字符串
  2. print(字符串)

以下为jupyter运行代码

#!/usr/bin/env python
coding: utf-8

Python的注释

  1. 单行注释 - 以#和空格开头的部分
  2. 多行注释
    “”"
    多行注释 - 三个引号开头,三个引号结尾
    “”"

Python输出函数

输出函数input ,输出类型为字符串

print("Hello World") 

##输出变量

import numpy as np
import matplotlib.pyplot as plt
t=np.arange(0,4,0.1)
plt.plot(t,t,t,t+2,t,t**2)
print(t) #输出变量t

Python输入函数input

price=input('input the stock price of Apple:')
price
type(price) #输入是字符串类型
price=int(input('input the stock price of Apple:')) #用int或float函数改变成我们需要的字符类型
price
type(price)
price=eval(input('input the stock price of Apple:')) #用eval()这个函数当成有效的Pyhton表达式来求值并返回计算结果
price
type(price)
举个栗子
x=input('Enter a number:')
x  #是字符串类型
x=int(input('Enter a number:'))
x

Python 续行

if signal=='red' and\  #'\'续行
car=='moving':
    car='stop'
elif signal=='green' and    car=='stop':
        car='moving'

缩进

#增加缩进表示语句块的开始

#用相同的缩进表示同级别语句块

#减少缩进表示语句块的退出

变量

变量名:引用对象;标识对象.
使用时需要给变量起一个名字,叫做变量名

变量名命名规则:

标识符:指Python中允许作为变量名 或 其他对象名称的有效符号
1、首字符是字母或下划线
2、其余可以是字母、下划线、数字
3、大小写敏感
#variable
p=3.14 #做了赋值操作。p是变量名,表示后面的浮点数
myString='variable' #myString代表后面的字符串
pi='one word'

避免使用 首字符是下划线 的变量

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值