Basic data type, java Basic Data Type

Source: Internet
Author: User

Basic data type, java Basic Data Type
1. Numbers

 

1 >>> 7 + 3 # Addition 2 10 3 >>> 7-3 # subtraction 4 4 4 5 >>> 7*3 # multiplication 6 21 7 >>> 7/3 # Division 8 2 9 >>> 5 ** 2 # Multiplication Side 10 2511 >>>> 7% 3 # evaluate the remainder 12 113 >>>> a = 7.0/2 # float divided by int, result: float14 >>> print a, type (a) 15 3.5 <type 'float'>
2. Strings
 1 >>>word=’Python’ 2 >>>word[0] 3 ‘P’ 4 >>>word[5] 5 ‘n’ 6 >>>word[-1] 7 ‘n’ 8 >>>word[-2] 9 ‘o’10 >>>word[-6]11 ‘P’12 13 >>>word[0:2]14 ‘Py’15 >>>word[2:5]16 ‘tho’17 >>>word[:2]18 ‘Py’19 >>>word[-2:]20 ‘on’21 >>>word[:2]+word[2:]22 ‘Python’23 >>>len(word)24 6

+ --- +

| P | y | t | h | o | n |

+ --- +

0 1 2 3 4 5 6

-6-5-4-3-2-1

 

The sequence number of the string "Python", sorted from left to right by 0-6, from right to left (-1)-(-6)

 

3. Lists

 

1 >>> squares = [, 25] 2 >>> squares 3, 25] 4 >>> squares [0] 5 1 6 >>> squares [-1] 7 25 8 >>> squares [-3:] 9 [9, 16, 25] 10 >>> squares [:] # returns a copy of squares, that is, the new list11 [, 25] 12 >>>> squares +, 100] 13 [81,100,] 14 15> cubes =, 125] 16 >>> 4 ** 3 #4 cubes are 6417 64 18 >>> cubes [3] = 6419 >>>> cubes20 [, 64, 125] 21 >>> cubes. append (216) 22 >>> cubes. append (7 ** 3) 23 >>> cubes24 [125,216,343,] 25 26 >>> letters = ['A', 'B', 'C ', 'D', 'E', 'F', 'G'] 27> letters28 ['A', 'B', 'C', 'D ', 'E', 'F', 'G'] 29 >>> letters [2: 5] = ['C', 'D ', 'E'] 30 >>> letters31 ['A', 'B', 'C', 'D', 'E', 'F ', 'G'] 32 >>> letters [2: 5] = [] 33 >>> letters34 ['A', 'B', 'F ', 'G'] 35 >>> letters [:] = [] 36 >>> letters37 [] 38 39 >>> letters = ['A', 'B ', 'C', 'D'] 40 >>> len (letters) 41 442 43 >>> a = ['A', 'B ', 'C'] 44 >>> n = [1, 2, 3] 45 >>> x = [a, n] 46 >>> x47 [['A ', 'B', 'C'], [1, 2, 3] 48 >>> x [0] 49 ['A', 'B ', 'C'] 50 >>> x [0] [1] 51 'B'

 

4. Summary

Variables do not need to be declared or deleted. They can be recycled directly.

Type (): query data type

Difference between String and List: String can only be read. It cannot be replaced by an equal sign (=) value assignment. List can be read. It can also be replaced by an equal sign (=) value assignment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.