Python_Script - Getting Started

一日平安一日福,一日快乐一日仙

原文英文出处

环境

python3
Windows

打开终端进入 python 解释器,下面定义两个变量,并使用 type() 函数查看变量的类型。

>>> ip = '8.8.8.8'
>>> port = 80
>>> type(ip)
<class 'str'>
>>> type(port)
<class 'int'>
>>>

使用 help() 可以了解对应函数更多的信息

>>> help(str)
Help on class str in module builtins:

class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |
 |  Create a new string object from the given object. If encoding or
 |  errors is specified, then the object must expose a data buffer
 |  that will be decoded using the given encoding and error handler.
 |  Otherwise, returns the result of object.__str__() (if defined)
 |  or repr(object).
 |  encoding defaults to sys.getdefaultencoding().
 |  errors defaults to 'strict'.
 |
 |  Methods defined here:

使用 + 连接两个字符串,因为 portint 类型,所以需要使用 str() 函数对其进行转换为 string 类型

>>> print("The IP is: " + ip + " and the port is: " + str(port))
The IP is: 8.8.8.8 and the port is: 80
>>>

对于字符串还可以进行 索引切片取长度
PS: 索引如果是负值将从右侧开始计数,负的索引从 -1 开始

>>> domain = 'zhutou.com'
>>> domain
'zhutou.com'
>>> domain[3]
't'
>>> domain[3:7]
'tou.'
>>> domain[8:]
'om'
>>> len(domain)
10
>>>

dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法 __dir__(),该方法将被调用。如果参数不包含 __dir__(),该方法将最大限度地收集参数信息。

>>> dir(ip)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>

split 方法可以将字符串分割成列表,可以使用 help() 函数查看 split 方法的效果

>>> help(ip.split)
Help on built-in function split:

split(...) method of builtins.str instance
    S.split(sep=None, maxsplit=-1) -> list of strings

    Return a list of the words in S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string is a separator and empty strings are
    removed from the result.

>>> string = ip + ':' + str(port)
>>> string
'8.8.8.8:80'
>>> string.split(':')
['8.8.8.8', '80']
>>>

同时可以使用索引获取列表中对应的值,使用 appendremove 方法对列表进行增删操作

>>> list = string.split(':')
>>> list
['8.8.8.8', '80']
>>> list.append('zhutou')
>>> list
['8.8.8.8', '80', 'zhutou']
>>> list.remove('zhutou')
>>> list
['8.8.8.8', '80']
>>> list[0]
'8.8.8.8'
>>>

文件的读写操作

>>> file = open('test.txt','w')
>>> file.write('Hello World')
11
>>> file.close()
>>> file = open('test.txt','r')
>>> file.readlines()
['Hello World']
>>>

python3 的基础巩固可以参考菜鸟教程

                                                                                                                                                                   猪头
                                                                                                                                                                2020.3.27
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值