云中客

梦想有多大,就能走多远

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  118 随笔 :: 4 文章 :: 169 评论 :: 0 引用

OSX从Pthon 2.7升级到3.8

1,官网下载最新安装包安装

2,执行认证文件command

3,执行设置path command

4,设置默认python

在terminal里运行open  ~/.bash_profile,打开~/.bash_profile,直接修改文件保存,重启Terminal。

source ~/.bash_profile

# Setting PATH for Python 3.8

# The original version is saved in .bash_profile.pysave

export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/3.8/bin:

alias python="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8"

Print练习

>>> print("hello world")
hello world
>>> 
>>> 
>>> ms="good morning"
>>> print(ms)
good morning
>>> 
>>> 
>>> ms=2
>>> print(ms)
2

字符串操作

title:首字母大写

upper:全大写

lower:全小写

strip:去掉两头空格

lstrip:去掉左边空格

rstrip:去掉右边空格

+:链接字符串

>>> ms="li xiaobin"
>>> 
>>> print(ms.upper())
LI XIAOBIN
>>> 
>>> print(ms.lower())
li xiaobin
>>> 
>>> print(ms.title())
Li Xiaobin
>>> 
>>> ms=" li xiao bin "
>>> 
>>> print(ms.strip())
li xiao bin
>>> 
>>> print(ms)
 li xiao bin 
>>> print(ms.lstrip())
li xiao bin 
>>> 
>>> print(ms.rstrip())
 li xiao bin
>>> 
>>> 
>>> print('li'+ms)
li li xiao bin 
>>> 

代码注释

# hello world
print("hello ¥n li xiaobin")

如果多行注释可以使用如下方法:

''' 
many lines hello world

by lixiaobin
'''
print("hello ¥n li xiaobin")

 

posted on 2019-11-13 23:32  走遍江湖  阅读(51)  评论(0编辑  收藏