博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python Beginners Guide摘抄
阅读量:6605 次
发布时间:2019-06-24

本文共 2690 字,大约阅读时间需要 8 分钟。

就当是学计算机英语

Beginners Guide  

Python is used as a server side language.

it can output HTML.

Python is space sensitive.

it is one of the simplest looking languages.?

Two ways to comment in Python:

Single line: #comment

Multiple line:

'''

comments

'''

Variables are awesome asset to the dynamic world of the web.?

Python interprets and declares variables for you when you set them equal to a value.

cast type to another type:int(variable)   str(variable)  float(variable)

Python operations:

print(3/4)#0.75

print(3**4)#3 to the fourth power

print(3//4)#floor division

 % is called the modulus operator.

= is called assignment operator.

we are programmers and we are proud to be called lazy.

The if statement is a conditional that ,when it is satisfied ,activates some part of code.

Python's else if is shortened into elif.

If statements are generally coupled with variables to produce more dynamic content.

Python's syntax is a lot cleaner then other languages ,this also means it is very picky and tends to bite beginners with errors.

 It is necessary to define functions before they are called.

Python does support global variables without you having to explicitly express that they are global variables.

The do-while loop isn't in Python.

-------------------------------

Common String Methods in Python

  • stringVar.count('x') - counts the number of occurrences of 'x' in stringVar
  • stringVar.find('x') - returns the position of character 'x'    return -1 if 'x' is not contained in the stringVar
  • stringVar.lower() - returns the stringVar in lowercase (this is temporary)
  • stringVar.upper() - returns the stringVar in uppercase (this is temporary)
  • stringVar.replace('a', 'b') - replaces all occurrences of a with b in the string这里的描述不准确,容易引起误会。这句话其实描述的是replace函数的返回值,strip也是
  • stringVar.strip() - removes leading/trailing white space from string

-------------------------------

A negative number in an index means that you want python to calculate the index starting from the end and moving towards the front aka backwards.

Common List Methods

  • .append(value) - appends element to end of the list
  • .count('x') - counts the number of occurrences of 'x' in the list
  • .index('x') - returns the index of 'x' in the list
  • .insert('y','x') - inserts 'x' at location 'y'
  • .pop() - returns last element then removes it from the list
  • .remove('x') - finds and removes first 'x' from list
  • .reverse() - reverses the elements in the list      逆序
  • .sort() - sorts the list alphabetically in ascending order, or numerical in ascending order
    • 排序,同时包含数字和字符串时不能排序
    •   slist.sort()

      TypeError: '<' not supported between instances of 'str' and 'int'

 Python 是解释型语言

Tuple的格式就像JSON

转载于:https://www.cnblogs.com/afraidToForget/p/6576756.html

你可能感兴趣的文章
dell r620装cenots7遇到的问题
查看>>
Ansible之playbook的使用
查看>>
ansible模块批量管理
查看>>
redis命令 - GET
查看>>
[Maven问题总结]Jetty9的Maven配置——嵌入式服务器
查看>>
httpd.conf的基本设置
查看>>
RHEL/Centos7新功能
查看>>
第一部分 思科九年 一(1)
查看>>
DBA日常工作职责
查看>>
Redis的持久化
查看>>
linux安装NFS服务器学习
查看>>
Planner .NET日历日程控件能给你的应用程序提供多种日历日程功能
查看>>
我的友情链接
查看>>
Linux压力测试
查看>>
JAVA中的线程机制(二)
查看>>
nginx安装与配置2(转载)
查看>>
Linux下Mongodb安装和启动配置
查看>>
2015 成长计划
查看>>
沈阳一饭店凌晨爆燃,燃气报警器时刻预防
查看>>
Redis 与 数据库处理数据的两种模式
查看>>