美文网首页Python中文社区R. python新手日记
python输出emoji表情?一些有趣的code分享

python输出emoji表情?一些有趣的code分享

作者: 生信编程日常 | 来源:发表于2019-12-30 20:44 被阅读0次

​今天在网上冲浪的时候看到一些有趣的内容,感觉特别有意思,来分享一下。

  1. emoji表情
$ pip install emoji
from emoji import emojize
print(emojize(":thumbs_up:"))

输出:

image

或者:

import emojis
emojis.encode('This is a message with emojis :smile: :snake:')
image

2. all / any

x = [True, True, False]
if any(x):
    print("At least one True")
if all(x):
    print("Not one False")
if any(x) and not all(x):    
    print("At least one True and one False")
  1. 在控制台中画图 (bashplotlib)
$ pip install bashplotlib
$ scatter -x test4.txt -y test5.txt # x和y提供x轴数据和y轴数据

输出:

image

4. Wiki

import wikipedia
​
result = wikipedia.page('Biology')
print(result.summary)
image

5. __future__

# 比如python2与python3的一个区别就是除法的不同,在Python2中使用真正的除法:
from __future__ import division
3 / 2
# 现在会输出1.5,原来则会输出1.
  1. 数值交换
x, y = 2, 3
x,y = y,x
  1. lamda匿名函数
# 适用于懒得给函数起名字的时候
add = lambda x, y: x + y
add(1,2)
# 或者
(lambda x, y: x + y)(1, 2)
  1. Counter
from collections import Counter
test = [1,2,2,3,6,7,8,9,3,2,2,5]
cal_test = Counter(test)
print(cal_test.most_common(2))

Counter会统计出来每个元素出现的次数,most_common可返回出现最频繁的两个元素及其次数。collections这个包非常好用,比如里面的defaultdict方法,可以构建一个key对应多个value的字典。

参考:https://www.freecodecamp.org/news/an-a-z-of-useful-python-tricks-b467524ee747/

欢迎关注(´・ω・`)


python输出emoji表情?一些有趣的code分享

相关文章

网友评论

    本文标题:python输出emoji表情?一些有趣的code分享

    本文链接:https://www.haomeiwen.com/subject/iffvoctx.html