zoukankan      html  css  js  c++  java
  • python基础语法

    1、字符串的常见操作:

    虽然下标为-1表示的是最后一个元素,但是str1[0:-1]中,所表示的是一个前闭后开区间,就如range(a,b), 包括a但不包括b。

     2、print的常见操作

    print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end=""

    print(str1, end = " ")
    print(str1, end = " ")

    输出为:   runoob runoob 

    3、导入操作

    将整个模块(somemodule)导入,格式为: import somemodule

    从某个模块中导入某个函数,格式为: from somemodule import somefunction

    从某个模块中导入多个函数,格式为: from somemodule import firstfunc, secondfunc, thirdfunc

    将某个模块中的全部函数导入,格式为: from somemodule import *

    4、命令行参数

    很多程序可以执行一些操作来查看一些基本信息,Python可以使用-h参数查看各参数帮助信息:

    $ python -h
    usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
    Options and arguments (and corresponding environment variables):
    -c cmd : program passed in as string (terminates option list)
    -d     : debug output from parser (also PYTHONDEBUG=x)
    -E     : ignore environment variables (such as PYTHONPATH)
    -h     : print this help message and exit
    
    [ etc. ]

    以上内容参考:https://www.runoob.com/python3/python3-basic-syntax.html

    5、python的基本数据类型

    Python 中的变量不需要声明。每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。在 Python 中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型。

    (1)可以同时为多个变量赋值

    1 a = b = c = 1
    2 print(a, b, c)
    3 a, b, c = 1, 2, 3
    4 print(a, b, c)

    结果为 :1 1 1

        1 2 3

    (2)Python3 的六个标准数据类型中:

    • 不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
    • 可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。
  • 相关阅读:
    平分糖果——BZOJ 1045
    浙大月赛——ZOJ Problem Set 3574
    jsp 自定义标签的写法
    C#扩展方法(转贴)
    window mobile 防止系统休眠代码
    jbpm sql使用动态参数方法
    spring 多数据源配置实现
    原创jquery蒙版控件
    jbpm 错误解决方法
    cas server 配置
  • 原文地址:https://www.cnblogs.com/liliwang/p/12670498.html
Copyright © 2011-2022 走看看