package day01; public class Program { public static void main(String[] args) { // TODO Auto-generated method stub char x='x'; int i=10; System.out.println(false?i:x); System.out.println(false?10:x); /*第一个因为i是一个变量,因此,第一个输出x被提升为
我们知道Python没有三元表达式,但是我们通过技巧达到三元表达式的效果. 摘自<Dive Into Python>: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际进行比较的值之一. and 介绍 >>> 'a' and 'b' #1 'b' >>> '' and 'b' #2 '' >>> 'a' and 'b' and 'c' #3 'c' 1 使用 and 时,在
一 三元表达式.列表推导式.生成器表达式 一 三元表达式 name=input('姓名>>: ') res='SB' if name == 'alex' else 'NB' print(res) 二 列表推导式 #1.示例 egg_list=[] for i in range(10): egg_list.append('鸡蛋%s' %i) egg_list=['鸡蛋%s' %i for i in range(10)] #2.语法 [expression for item1 in iterabl