zoukankan      html  css  js  c++  java
  • python学习第一天

    一.python的数据类型
    整数:程序表示上和数学上的写法一样,例如,1,100,-800等。
    浮点数:小数。
    字符串:以''或者" "扩起来的任意文本,‘本身也可作为一个字符
    转义字符: 表示换行 表示制表符 本身也要转义 \表示 需要加很多的时候为了 简化,使用r''表示''
    布尔值:布尔值和布尔代数的表示完全一致,一个布尔值只有true 、False两种值,在python中直接可以使用Ture和False
    空值:空值是python里的一个特殊的值,用none表示,none不能理解为0
    常量:其值不能改变的变量,在python中,通常用全部大写的变量名表示常量,如PI=3.14
    %d 整数
    %f 浮点数
    %s 字符串
    %x 十六进制数
    条件判断
    age = 20 if age >= 18: print('your age is', age) print('adult')
    #
    age = 3 if age >= 18: print('your age is', age) print('adult') else: print('your age is', age) print('teenager')
    if <条件判断1>: <执行1> elif <条件判断2>: <执行2> elif <条件判断3>: <执行3> else: <执行4>
    输入输出
    input
    循环
    names = ['Michael', 'Bob', 'Tracy'] for name in names: print(name)
     
    循环
    dic和set
    与list比较,dict有以下几个特点:
    1.查找和插入速度极快,不会随着key的增加而变慢
    2.需要占用大量的内存,内存浪费多。
    函数
    在python中,定义一个函数要使用def语句,依次写出函数名、括号、括号中的参数和冒号:在缩进块中编写函数体,函数的返回值用return语句。
    def greet_user():
    print ("hello world!")
    greet_user()
    向函数传递信息
    实参和形惨
    实参:给变量一个指定的值。
    形参:给变量一个形参,函数完成其工作所需要的一项信息。
     
    cars=['audi','bmw','subaru','toyota']
    for car in cars:
    if car=='bmw':
    print (car.upper())
    else:
    print(car.title())
    age=12
    if age <4:
    print ("Your admission cost is $0.")
    elif age <18:
    print ("Your admission cost is $5.")
    else:
    print ("Your admission cost is $10.")
     
    age=12
    if age <4:
    price=0
    elif age<18:
    price=5
    elif age <65:
    price=10
    else:
    price=5
    print ("Your admission cost is $"+str(price)+".")
     
    字典
    alien_0={'color':'green','point':5}
    print (alien_0['color'])
    print (alien_0['point'])
     
    alien_0={'color':'green','points':5}
    new_points=alien_0['points']
    print ("You just earned"+str(new_points)+"points!")
     
     
    alien_0={}
    alien_0['color']='green'
    alien_0['points']=5
    print (alien_0)
     
     
    alien_0={'color':'green'}
    print ("The alien is"+alien_0['color']+".")
    alien_0['color']='yellow'
    print ("The alien is now:"+alien_0['color']+".")
     
    输入输出
    name=raw_input("Please enter Your name:")
    print ("Hello,"+name+"!")
     
    height=raw_input("How tail are you,in inches?")
    height=int(height)
    if height>=36:
    print (" You're tall enough to ride!")
    else:
    print (" You'll be able to ride when you're a little older.")
     
     
    x=1
    while x <=5:
    print (x)
    x+=1
     
    函数
    # -*- coding: UTF-8 -*-
    def greet_user():
    print ("Hello!")
    greet_user()
     
    向函数传递参数
    实参和形参
     
    python的模块
    python的模块是一个文件,以.py结尾
    def print_func( par ):
    print "Hello : ", par
    return
    导入特定的函数
    from module_name import function1,fuction2,fuction3
    在python中,根据约定,首字母大写的 名称指的是类。
    ——init_()默认创建
    class Dog():
    def __init__(self,name,age):
    self.name=name
    self.age=age
    def sit(self):
    print (self.name.title()+"is now sitting.")
    def roll_over(self):
    print (self.name.title()+"rolled over!")
     
    第80页
  • 相关阅读:
    ftp实现普通账号和vip账号限速
    CentOS7 无人值守服务环境搭建(PXE + DHCP+TFTP+ Kickstart+ FTP)
    rsync 系统用户/虚拟用户 备份web服务器数据及无交互定时推送备份
    LVM逻辑卷管理
    Linux允许、禁止ping包
    javascript call 与 apply
    js 内存进阶 function扫描解析
    事件绑定之鼠标悬停 -入门-进阶-精通-骨灰(来自锋利的jQuery)
    show(),hide()和display在一起的用法
    Nat模式下网卡配置及Xshell连接
  • 原文地址:https://www.cnblogs.com/networking/p/11096873.html
Copyright © 2011-2022 走看看