Jython Language Learning Notes

Source: Internet
Author: User
Tags new set shallow copy

1. Variables can be arbitrarily defined, without limiting the type, without limiting the value. Empty 4 spaces at the beginning, use DEF to define functions, can be nested, can be passed.

2. There is no semicolon at the end of each statement. There is no parentheses when defining a class. After the print statement there is a format conversion to add%, for and while after the colon, shortcut keys I changed to Ctrl+r and D

Method Description of functionality
Capitalize () Returns a capitalized copy of string
Center (Width[,fill]) Returns a repositioned string with specified width and provide optional padding filler character
Count (Sub[,start[,end]]) Count the number of distinct times the substring occurs within the string
Decode ([encoding[,errors]]) Decodes and returns Unicode string
Encode ([encoding[,errors]]) Returns an encoded version of a string
EndsWith (Suffix[,start[,end]) Returns A Boolean to state whether the string ends in a given pattern
Expandtabs ([tabsize]) Converts tabs within a string into spaces
Find (Sub[,start[,end]) Returns the index of the position where the first occurrence of the given substring begins
Index (Sub[,start[,end]) Returns the index of the position where the first occurrence of the given substring begins. Raises a valueerror with the substring are not found.
Isalnum () Returns A Boolean to state whether the string contain only alphabetic and numeric characters
Isalpha () Returns A Boolean to state whether the string contains all alphabetic characters
IsDigit () Returns A Boolean to state whether the string contains all numeric characters
Islower () Returns A Boolean to state whether a string contains all lowercase characters
Isspace () Returns A Boolean to state whether the string consists of all whitespace
Istitle () Returns A Boolean to state whether the first character of all word in the string is capitalized
Isupper () Returns A Boolean to state whether all characters within the string is uppercase
Join (Sequence) Returns a copy of sequence joined together with the original string placed between each element
Ljust (Width[,fillchar]) Returns A string of the specified width along with a copy of the original string at the leftmost bit. (Optionally padding empty space with Fillchar)
Lower () Returns a copy of the original string with all characters in the string converted to lowercase
Lstrip ([chars]) Removes the first found characters in the "the left" match the given characters. Also removes whitespace from the left. Whitespace removal is the default when specified with no arguments.
Partition (separator) Returns a partitioned string starting from the left using the provided separator
Replace (Old,new[,count]) Returns a copy of the original string replacing the portion of string given in and the portion given in new
RFind (Sub[,start[,end]) Searches string from finds the first occurrence of the given string and returns highest index where sub is found
Rindex (Sub[,start[,end]) Searches string from finds the first occurrence of the given string and either returns highest index whe Re sub is found or raises an exception
Rjust (Width[,fillchar]) Returns copy of String Aligned to the right by width
Rpartition (separator) Returns a copy of stringpartitioned starting from the right using the provided separator object
Rsplit ([Separator[,maxsplit]]) Returns list of words in strings and splits the string from the right side and uses the given separator as a delimiter. If Maxsplit is specified then at most maxsplit splits be done.
Rstrip ([chars]) Returns copy of string removing the first found characters in the string from the right to match those given. Also removes whitespace from the right if no argument is specified.
Split ([Separator[,maxsplit]) Returns a list of words in strings and splits the string from the left side and uses the given separator as a delimiter.
Splitlines ([keepends]) Splits the string into a list of lines. Keepends denotes if newline delimiters is removed. Returns the list of lines in the string.
StartsWith (Prefix[,start[,end]) Returns A Boolean to state whether the string starts with the given prefix
Strip ([chars]) Returns a copy of string with the given characters removed from the string. If no argument is specified then whitespace is removed.
Swapcase () Returns a copy of the character in the string converted.
Title () Returns a copy of the string with the first character in each word uppercase.
Translate (Table[,deletechars]) Returns a copy of the string using the given character translation table to translate the string. All characters occurring in optional deletechars argument is removed.
Upper () Returns a copy of string with any of the characters in the string converted to uppercase
Zfill (width) Returns A numeric string padded from the left with zeros for the specified width.
D Signed integer decimal
I Signed integer
O unsigned octal
U unsigned decimal
X unsigned hexidecimal (lowercase)
X unsigned hexidecimal (uppercase letters)
E Floating point exponential format (uppercase ' E ')
E Floating point exponential format (lowercase ' e ')
F Floating point decimal format (lowercase)
F Floating point decimal format (same as ' F ')
G Floating point exponential format if exponent < -4, otherwise float
G Floating point exponential format (uppercase) if exponent < -4, otherwise float
C Single character
R String (converts any Python object using repr ())
S String (converts any Python object using str ())
% No conversion, results in a percent (%) character if specified twice

3. The string in Jython is as immutable as Java.

4. A slider list is a start number that contains no ending number. The pop () is also remove. The Remove () operation can only delete the first match.

Index Returns the index of the first value in the list which matches a given value.
Count Returns the number of items in the list which equal a given value.
Sort Sorts the items contained within the list and returns the list
Reverse Reverses the order of the items contained within the list, and returns the list

5. The difference between an array and a list is that the list can be changed, and the array cannot be changed.

Method or Function Description
Len (dictionary) Function that returns number of items within the given dictionary.
Dictionary [key] Returns the item from the dictionary, that's associated with the given key.
Dictionary[key] = value Sets the associated item in the dictionary to the given value.
Del Dictionary[key] Deletes the given key/value pair from the dictionary.
Dictionary.clear () Method that removes all items from the dictionary.
Dictionary.copy () Method that creates a shallow copy of the dictionary.
Has_key (Key) Function that returns a Boolean stating whether the dictionary contains the given key. (Deprecated in favor of with using in ')
Key in D Returns a Boolean stating whether the given key is found in the dictionary
Key not in D Returns a Boolean stating whether the given key is not found in the dictionary
Items () Returns a list of tuples including a copy of the Key/value pairs within the dictionary.
Keys () Returns The A list of keys within the dictionary.
Update ([Dictionary2]) Updates dictionary with the Key/value pairs from the given dictionary. Existing keys would be overwritten.
Fromkeys (Sequence[,value]) Creates a new dictionary with keys from the given sequence. The values would be set to the value given.
VALUES () Returns the values within the dictionary as a list.
Get (key[, b]) Returns the value associated with the given key. If The key does not exist and then returns B.
SetDefault (key[, b]) Returns the value associated with the given key. If The key does not exist and then the key value was set to B (Mydict[key] = b)
Pop (key[, b]) Returns and removes the key/value pair associated with the given key. If The key does not exist then returns B.
Popitem () An arbitrary key/value pair are popped from the dictionary
Iteritems () Returns an iterator over the key/value pairs in the dictionary.
Iterkeys () Returns an iterator over the keys in the dictionary.
Itervalues () Returns an iterator over the values in the dictionary.

6. Sets is unordered, and can not be repeated, DIC is repeatable, sets must be added before using the package from sets import set

Method or operation Description
Len (SET) Returns the number of elements in a given set
Copy () Returns a new shallow copy of the set
Difference (Set2) Returns A new set contains all elements that is in the calling set, and not in Set2
Intersection (SET2) Returns A new set contains all elements the calling set and Set2 has in common
Issubbset (Set2) Returns a Boolean stating whether all elements in calling set is also in Set2
Issuperset (Set2) Returns a Boolean stating whether all elements in Set2 is contained in calling set
Symmetric_difference (Set2) Returns a new set containing elements either from the calling set or Set2 and not from both (set1 ^ set2)
X in Set Tests whether X is contained in the set, returns Boolean
X not in Set
Tests whether x isn't contained in the set, returns
Boolean
Union (Set2) Returns a new set containing elements that is contained in both the calling set and Set2
Method or operation Description
Add (item) Adds an item to a set if it's not already in the set
Clear () Removes all items in a set
Difference_update (Set2) Returns the set with all elements contained in Set2 removed
Discard (Element) Removes designated element from set if present
Intersection_update (Set2) Returns the set keeping only those elements that is also in Set2
Pop () Return an arbitrary element from the set
Remove (Element) Remove element from the set if present, if not then Keyerror is raised
Symmetric_difference_update (Set2) Replace the calling set with a set containing elements from either the calling set or Set2 but not both, and return it
Update (SET2) Returns set including all elements from Set2

7. Read () and ReadLines () reads the contents of the format is not the same, if the current location is at the end of the file must seek, otherwise read out the content.

8. In the string and list, you do not have to create an iterator, or you can use for to iterate. If you assign an immutable object to another variable, such as String and integer. The variable is the copy of the string, and changing the value of the variable does not change the string. If you assign a change to another variable, such as list. The variable is a reference to the list, that is, the same thing, changing the value of the variable will change the list at the same time. To get a copy of List (a), import copy and use B=copy.copy (a). But it's just a shallow copy. That is, different objects, but the same reference, although B is a false. But if you change the value of B, a will change the same. If you want to use Deepcopy, then import copy and then B=copy.deepcopy (a) so that the value of a will not change after you change the value of B.

Jython Language Learning Notes

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.